3 class mw_model_users extends mw_model{
7 // ----------------------------------------------------------------------------
10 function set_roles($roles){
11 $this->roles = $roles;
18 function clear_roles(){
22 function get_values(){
24 if(isset($this->roles)) $values["roles"] = $this->roles;
25 foreach($this->attributs as $attribut_name => $attribut){
26 $values[$attribut_name] = isset($attribut["value"]) ? $attribut["value"] : null;
31 function set_password($password){
32 $this->attributs["password"]["value"] = $this->encode_password($password);
35 function encode_password($password){
36 return md5($password);
39 // ----------------------------------------------------------------------------
42 function valid_email($email){
43 if(!isset($email) || !$email){
44 return "merci de préciser un email";
46 if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
47 return "le mail ne semble pas être un email valide";
52 function valid_login($login){
53 if(!isset($login) || !$login){
54 return "merci de préciser un login";
59 function valid_password($password){
60 if(!isset($password) || ($password == $this->encode_password(""))){
61 return "merci de préciser un mot de passe";
66 // ----------------------------------------------------------------------------
70 $data = $this->env->data();
71 $roles = $this->get_roles();
73 $RETURN_INSERT_ID = $this->RETURN_INSERT_ID;
74 $this->RETURN_INSERT_ID = true;
75 if(!($id_user = parent::insert())) return false;
76 $this->set_id($id_user);
77 $this->set_roles($roles);
78 $this->RETURN_INSERT_ID = $RETURN_INSERT_ID;
79 foreach($this->roles as $id_role){
80 if(!$data->add_user_role($this->get_id(), $id_role)) return false;
85 function load($index_name, $index_value){
86 $data = $this->env->data();
87 if(parent::load($index_name, $index_value) === false) return false;
89 if(($this->roles = $data->list_user_roles($this->get_id())) === false) return false;
94 function update($index_name, $index_value = null){
95 $data = $this->env->data();
96 $roles = $this->get_roles();
98 if(!($res = parent::update($index_name, $index_value))) return false;
99 $this->set_roles($roles);
100 if(!$data->clear_user_roles($this->get_id())) return false;
101 foreach($this->roles as $id_role){
102 if(!$data->add_user_role($this->get_id(), $id_role)) return false;
107 function delete($index_name, $index_value = null){
108 $data = $this->env->data();
109 if(!$data->clear_user_roles($this->get_id())) return false;
110 return parent::delete($index_name, $index_value);