public function actionIndex() { $user = new User(); if (!empty($_POST['User'])) { $user->attributes = $_POST['User']; if ($user->save()) { Yii::app()->user->login(UserIdentity::createAuthenticatedIdentity($user->username, $user->id), 0); echo json_encode(array('errors' => '')); } else { $errors = $user->getErrors(); echo json_encode(array('errors' => $errors)); } exit; } $this->render('index', array('model' => $user)); }
/** * running when login success */ public function actionSuccess() { $instagram = Yii::app()->instagram; // receive OAuth code parameter $code = $_GET['code']; // check whether the user has granted access if (isset($code)) { // receive OAuth token object $data = $instagram->getOAuthToken($code); $username = $data->user->username; $user_id = $data->user->id; $avatar = $data->user->profile_picture; // store user access token $instagram->setAccessToken($data); // now you have access to all authenticated user methods $result = $instagram->getUserMedia(); if ($data) { // save this information to db $user = new User('instagram_login'); $user->username = $username; $user->instagram_id = $data->user->id; $user->access_token = $instagram->getAccessToken($data); $user->full_name = $data->user->full_name; $user->avatar = $avatar; // check if instagram_id is unique then save to db $user = $user->zeroUnique(); if (!isset(Yii::app()->user->id)) { // login automatically Yii::app()->user->login(UserIdentity::createAuthenticatedIdentity($user->username, $user->id), 0); $this->redirect('/user/activity'); } $this->redirect('/user/account'); } else { throw new CHttpException('There are some issues with login on instagram.'); } } else { // check whether an error occurred if (isset($_GET['error'])) { echo 'An error occurred: ' . $_GET['error_description']; } } $this->render('success', array('result' => $result, 'username' => $username)); }
public function actionActivate($a) { if ($a != '') { $model = User::model()->find('activate=:a', array(':a' => $a)); d2l($model->attributes); if ($model) { // /$model->activate=''; if ($model->status != User::STATUS_ACTIVE) { $model->status = User::STATUS_ACTIVE; if ($model->update(array('status'))) { Yii::app()->user->login(UserIdentity::createAuthenticatedIdentity($model->username, $model->id), 0); d2l(Yii::app()->user->model->attributes); $this->render('activate', array('model' => $model, 'status' => 'success')); } } else { Yii::app()->user->logout(); $this->render('activate', array('model' => $model, 'status' => 'already')); } } else { throw new CHttpException(404, "Invalid Activation Code!"); } } }