Example #1
0
 public function put_index($id, $username, $email, $password = null, $id_group = null)
 {
     // Force to edit the current user if they don't have the proper permissions
     if (!$this->_currentUser->hasPermission(Model_Groups::PERM_MANAGE_USERS)) {
         $id = $this->_currentUser->getId();
     }
     $user = Model_Users::getById($id);
     $propsUpdate = ['username' => $username, 'email' => $email];
     if ($id_group !== null && !empty($id_group) && $this->_currentUser->hasPermission(Model_Groups::PERM_MANAGE_USERS)) {
         $group = Model_Groups::getById($id_group);
         $propsUpdate['usergroup'] = $group;
     } else {
         $user->load('usergroup');
     }
     if ($password !== null && !empty($password)) {
         $propsUpdate['password'] = Library_String::hash(trim($password));
     }
     $user->setProps($propsUpdate);
     Model_Users::update($user);
     // Disconnect the user if they changed their own profile
     if ($id === $this->_currentUser->getId()) {
         $this->response->redirect('../login/out', 200);
     } else {
         $this->response->redirect('../users', 200);
     }
 }
 public static function login($email, $password)
 {
     $password = Library_String::hash($password);
     $user = Model_Users::createRequest()->where('email=? AND password=?', [$email, $password])->getOnly(1)->exec();
     if (!empty($user)) {
         Library_Session::set('currentUser', serialize($user));
     }
     return $user;
 }