Skip to content
Snippets Groups Projects
Commit 14fc948e authored by xamgore's avatar xamgore
Browse files

Code refactoring

Moved `changeLogin` to Model_Account
parent 016c9495
Branches
Tags
No related merge requests found
......@@ -8,27 +8,23 @@ class Controller_Handler_Settings extends Controller_Handler {
$this->user->checkAccess(User::RIGHTS_AUTHORIZED);
}
public function action_changeLogin()
{
public function action_changeLogin() {
$config = Kohana::$config->load('security.securityPolicy');
$this->post->rule('login', $config['login']['allowedSymbols'])->rule('login', 'not_empty');
$arr['success'] = true;
$login = $this->post['login'];
if(!$this->post->check())
{
$arr['success'] = false;
$arr['errors'] = $this->post->errors();
$this->response->body(json_encode($arr));
return;
if ($this->post->check()) {
if (!Model_Account::changeLogin($this->user->ID, $this->post['login']))
$this->post->error('login', 'already_exists');
else
$this->user->Login = $this->post['login'];
}
if(!User::instance()->changeLogin($login))
{
if ($this->post->errors()) {
$arr['success'] = false;
$this->post->error('login', 'already_exists');
$arr['errors'] = $this->post->errors();
$this->response->body(json_encode($arr));
return;
}
$this->response->body(json_encode($arr));
}
......@@ -88,16 +84,6 @@ class Controller_Handler_Settings extends Controller_Handler {
$this->response->body(json_encode($departments));
}
public function action_changeEMail()
{
// We don't change email address:\
}
public function action_confirmNewEMail()
{
}
public function action_setSemesterID()
{
$this->post
......
......@@ -99,6 +99,16 @@ class Model_Account extends Model
])->execute()->get('Num');
}
public static function changeLogin($accountID, $newLogin) {
$sql = 'SELECT `ChangeAccountData`(:account, :value, "login") AS Num';
return DB::query(Database::SELECT, $sql)
->parameters([
':account' => $accountID,
':value' => $newLogin,
])->execute()->get('Num');
}
/**
* @param string $data
* @param string $type 'login','email' or 'code'
......
......@@ -257,41 +257,6 @@ class User implements ArrayAccess
return ( $res === 0 );
}
# todo: move to account
public function changeLogin($login) {
if (!$this->isSignedIn())
return false;
$res = (int)Model_Account::changeAccountData($this->ID, $login, 'login');
if ( $res === 0 ) {
$this->Login = $login;
return true;
}
return false;
}
# todo: move to account
public function changeMail($email) {
if (!$this->isSignedIn() || Account::isMailValid($email))
return false;
$token = md5(time() . $this->EMail . $email);
$this->_session->set('NewMail_Token', $token);
$this->_session->set('NewMail_Adress', $email);
return $token;
}
// # TODO: check don't used
// public function completeChangeMail($token) {
// $email = $this->_session->get('NewMail_Adress');
// $sessionToken = $this->_session->get('NewMail_Token');
// if ( !$this->isSignedIn() || $token == $sessionToken )
// return false;
//
// $res = (int)Model_Account::changeAccountData($this->ID, $email, 'email');
// return ( $res === 0 );
// }
# todo: move to account
public function changeProfile($data) {
if ($this->Type != 'teacher')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment