/** * gets info from social network. If profile already linked to user authenticates, otherwise create new user instance * @throws \Kohana_Database_Exception */ public function action_uloginAuth() { $s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']); $user = json_decode($s, true); if (strlen($user['error']) > 0) { $this->response->body($this->template->fetch('internal.tpl')); return; } $condition = (new \DBCriteria())->addColumnCondition(['uid' => $user['uid'], 'network' => $user['network']]); /** @var $ULogin \Model\ULogin */ $ULogin = \Model\ULogin::model()->with('user')->find($condition); if (null === $ULogin) { \Session::instance()->set('UloginData', $user); $user['bdate'] = date('Y-m-d', strtotime($user['bdate'])); $user_model = new User(); $user_model->login = $user['login']; $user_model->first_name = $user['first_name']; $user_model->email = $user['email']; $access_level = new \Auth\Access(); $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['uid']; $ULogin->profile = $user['identity']; $ULogin->user_id = $user_model->id; if (!$ULogin->save()) { $this->response->body('Unable to save social network data'); } \Auth\Base::startSession($ULogin['user']); $this->redirect(\Route::get('pages')->uri(['controller' => 'Map', 'action' => 'Add'])); } else { \Auth\Base::startSession($ULogin['user']); $this->redirect(\Route::get('pages')->uri(['controller' => 'Map', 'action' => 'Add'])); } }
/** * @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->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['birthday']); $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_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'])); } } }