public function saveEditData() { if (false !== ($user_id = Protect::Validate($this->request->param('id'), 'int'))) { /** @var $data \Model\Item */ $data = User::model()->findByPk($user_id); $keys = array_keys($_POST); foreach ($keys as $key) { $value = $_POST[$key]; if (!empty($value)) { if (!empty($_POST['pass'])) { $dynamic_salt = \Utils\Math::rand(); $pass = $_POST['pass'] . $dynamic_salt; $value = \Utils\Protect::Crypt($pass, $dynamic_salt); $data->salt = $dynamic_salt; } $data->{$key} = $value; } } if ($data->save()) { $this->response->body(json_encode(['code' => 0])); } else { throw new \HTTP_Exception_500('Id is not valid'); } } }
/** * */ public function action_saveData() { $user = \Session::instance()->get('UloginData'); $user_id = \Registry::getCurrentUser()->id; if ($user_id) { /** @var $data \Model\Item */ $data = User::model()->findByPk($user_id); $keys = array_keys($_POST); foreach ($keys as $key) { $value = $_POST[$key]; if ($value != '') { if ($key == "month" || $key == "year") { continue; } if ($key == "pass") { $dynamic_salt = \Utils\Math::rand(); $pass = $_POST['password'] . \Cookie::$salt; $value = \Utils\Protect::Crypt($pass, $dynamic_salt); $data->salt = $dynamic_salt; } if ($key == "day") { $date_birthday = date('Y-m-d', mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year'])); $data->date_birthday = $date_birthday; } else { $data->{$key} = $value; } } } if (!empty($_FILES['photo']['name'])) { $filename = $this->_save_image($_FILES['photo']); $data->photo = $filename; } if (!$data->save()) { $this->response->body('Error User Data'); } else { $this->redirect(\Route::get('pages')->uri(['controller' => 'Portfolio', 'action' => 'main'])); } } }
/** * @throws \Kohana_Database_Exception */ public function action_continue() { $user = \Session::instance()->get('UloginData'); if (!$user) { $this->response->body($this->template->fetch('internal.tpl')); return; } $dynamic_salt = \Utils\Math::rand(); $pass = $_POST['password'] . \Cookie::$salt; $crypted_pass = \Utils\Protect::Crypt($pass, $dynamic_salt); $user_model = new User(); $user_model->nickname = $_POST['nickname']; $user_model->first_name = $_POST['first_name']; $user_model->email = $_POST['email']; $user_model->salt = $dynamic_salt; $user_model->pass = $crypted_pass; $user_model->gender = $_POST['gender']; $user_model->date_birthday = strtotime($_POST['bdate']); $user_model->avatar = $_POST['avatar_url']; //TODO: uploaded file handler $access_level = new \Auth\Access(); /*Allow user to authenticate*/ $access_level->set(\Auth\Access::User_Login); $user_model->access_level = $access_level->getValue(); if (!$user_model->save()) { throw new \Kohana_Database_Exception('Unable to save user model'); } $ULogin = new ULogin(); $ULogin->network = $user['network']; $ULogin->uid = $user['identity']; $ULogin->user_id = $user_model->id; if (!$ULogin->save()) { $this->response->body('Unable to save social network data'); } else { $this->redirect(\Route::get('')->uri()); } }
public function action_recovery() { $action_status = ''; if ($recovery = $this->request->post('recovery')) { $action_status = ''; $criteria = (new \DBCriteria())->addCondition('recovery', $recovery); $criteria->condition = " lifetime > :lifetime "; $criteria->params = array(':lifetime' => time()); $userInfo = User::model()->find($criteria); if (($userInfo = User::model()->find($criteria)) && !empty($_POST['pass'])) { $dynamic_salt = Math::rand(); $pass = $_POST['pass'] . \Cookie::$salt; $crypted_pass = Protect::Crypt($pass, $dynamic_salt); $userInfo->pass = $crypted_pass; $userInfo->salt = $dynamic_salt; $userInfo->recovery = ''; if ($userInfo->save()) { $action_status = 'Password Changed!'; } } } else { $recovery = $this->request->param('recovery'); } $this->template->assign(['action_status' => $action_status, 'recovery' => $recovery]); $this->response->body($this->template->fetch('portfolio/recovery.tpl')); }
/** * @return bool|int */ public static function create($data) { $dynamic_salt = Math::rand(); $pass = $data['pass'] . $dynamic_salt; $crypted_pass = Protect::Crypt($pass, $dynamic_salt); $user_data = new User(); //$user_data->login = $data['login']; $user_data->email = $data['email']; $user_data->first_name = $data['first_name']; $user_data->phone = $data['phone']; if ($data['last_name']) { $user_data->last_name = $data['last_name']; } $user_data->pass = $crypted_pass; $user_data->gender = $data['gender']; $user_data->date_birthday = strtotime($data['birthday']); $user_data->salt = $dynamic_salt; $access_level = new Access(); /*Разрешаем юзверю банально логинится*/ $access_level->set(Access::User_Login); $user_data->access_level = $access_level->getValue(); if ($user_data->save()) { return $user_data; } else { return false; } }