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
No related merge requests found
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Handler_Settings extends Controller_Handler {
public function before() {
parent::before();
$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;
$arr['success'] = true;
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));
}
public function action_changePassword()
{
$config = Kohana::$config->load('security.securityPolicy');
$this->post
->rule('password', 'min_length', array(':value', $config['password']['length']))
->rule('confirm_password', 'matches', array(':validation', 'confirm_password', 'password'));
$arr['success'] = true;
$arr['success'] = true;
$old = $this->post['old_password'];
$new = $this->post['password'];
if(!$this->post->check())
......@@ -56,9 +52,9 @@ class Controller_Handler_Settings extends Controller_Handler {
$this->response->body(json_encode($arr));
return;
}
$this->response->body(json_encode($arr));
$this->response->body(json_encode($arr));
}
public function action_editProfile()
{
$this->user->checkAccess(User::RIGHTS_TEACHER);
......@@ -87,17 +83,7 @@ class Controller_Handler_Settings extends Controller_Handler {
$departments = $faculty->getDepartments();
$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
......@@ -108,4 +94,4 @@ class Controller_Handler_Settings extends Controller_Handler {
User::instance()->SemesterID = $semesterID; // todo: should work fine
}
}
}
\ No newline at end of file
}
......@@ -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% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment