/** * Check the user is authenticated * @return boolean */ protected function checkAuthenticated() { // Create user if (!$this->user) { $this->user = new \Sonic\Model\User(); } // Check authenticated $auth = $this->user->initSession(); if ($auth !== TRUE) { switch ($auth) { case 'invalid_session': new Message('error', 'Please login to continue'); break; case 'user_read_error': new Message('error', 'There seems to be a problem, please login to continue'); break; case 'inactive': new Message('error', 'Account not activated'); break; case 'timeout': new Message('error', 'Your session has expired, please login to continue'); break; } $this->template = $this->authModule ? strtolower($this->authModule) . '/' : NULL; $this->template .= 'login.tpl'; return FALSE; } // Return return TRUE; }
/** * Check the user is authenticated * @param string $session_id Session ID * @return boolean */ protected function checkAuthenticated($session_id = FALSE) { // Create user if (!$this->user) { $this->user = new \Sonic\Model\User($session_id); } // Check authenticated $auth = $this->user->initSession(); if ($auth !== TRUE) { return $this->authFail($auth); } // Return return TRUE; }
/** * Edit user * @param string $edit_user (Optional) Whether to edit a user * @param string $user_id User ID * @param string $user_first_name First name * @param string $user_last_name Last name * @param string $user_email Email address * @param string $user_active Active status * @param string $user_admin Admin status * @param string $user_password (Optional) New password * @param string $user_password_confirm (Optional) Password confirmation */ public function edit() { $id = $this->getArg('id'); if (!\Sonic\Model\User::_IDexists($id)) { new \Sonic\Resource\Redirect('index', array('error' => 'Invalid User')); } $user = \Sonic\Model\User::_read($id); $this->view->assignByRef('newuser', $user); if ($this->getArg('edit_user')) { // User data $user->fromPost(TRUE, array('first_name', 'last_name', 'email', 'active', 'admin')); if (\Sonic\Message::count('error')) { return FALSE; } // New password $exclude = array(); if ($user->get('password')) { if ($user->get('password') !== $this->getArg('user_password_confirm')) { new \Sonic\Message('error', 'The new passwords did not match, please try again'); return; } } else { $exclude[] = 'password'; } // Update if (!$user->update($exclude)) { new \Sonic\Message('error', 'User update failed, please try again'); return; } // Success $user->read(); new \Sonic\Message('success', 'User Updated'); } }
/** * Delete user * @return integer $id User ID */ public function delete() { $id = $this->getArg('id'); if (!ctype_digit($id) || !\Sonic\Model\User::_IDexists($id)) { return $this->error('Invalid User'); } if (!\Sonic\Model\User::_delete($id)) { return $this->error('Unable to delete user'); } else { return $this->success(); } }
/** * Authenticate user * @param string $username Username * @param string $password Password */ public function login() { $username = $this->getArg('username'); $password = $this->getArg('password'); if (!$username) { return $this->error('invalid username'); } if (!$password) { return $this->error('invalid password'); } if (\Sonic\Model\User::_Login($username, $password) instanceof \Sonic\Model\User) { $this->success(); } else { return $this->error('incorrect username and/or password'); } }
/** * Authenticate user * @param string $username Username * @param string $password Password */ public function login() { $username = $this->getArg('username'); $password = $this->getArg('password'); $this->template = 'admin/login.tpl'; if (!$username) { new \Sonic\Message('error', 'Invalid username'); return; } if (!$password) { new \Sonic\Message('error', 'Invalid password'); return; } if (\Sonic\Model\User::_Login($username, $password) instanceof \Sonic\Model\User) { new \Sonic\Resource\Redirect('/admin/index'); return; } else { new \Sonic\Message('error', 'incorrect username and/or password'); return; } }