Exemplo n.º 1
0
 public function updateIndex($userUid)
 {
     $user = User::getIndex($userUid);
     if (!$user) {
         return Response('Could not find user.', 500);
     }
     // send verification email
     //
     if ($user->email != Input::get('email')) {
         $emailVerification = new EmailVerification(array('user_uid' => $user->user_uid, 'verification_key' => GUID::create(), 'email' => Input::get('email')));
         $emailVerification->save();
         $emailVerification->send('#verify-email', true);
     }
     // set attributes
     //
     $user->first_name = Input::get('first_name');
     $user->last_name = Input::get('last_name');
     $user->preferred_name = Input::get('preferred_name');
     $user->username = Input::get('username');
     $user->address = Input::get('address');
     $user->phone = Input::get('phone');
     $user->affiliation = Input::get('affiliation');
     // update user
     //
     $user->modify();
     // get meta attributes
     //
     $attributes = array('email_verified_flag' => Input::get('email_verified_flag'), 'enabled_flag' => Input::get('enabled_flag'), 'owner_flag' => Input::get('owner_flag'), 'admin_flag' => Input::get('admin_flag'));
     // update meta attributes
     //
     $currentUser = User::getIndex(Session::get('user_uid'));
     if ($currentUser && $currentUser->isAdmin()) {
         // update user account
         //
         $userAccount = $user->getUserAccount();
         $userAccount->setAttributes($attributes, $user);
     }
     // return response
     //
     return $user;
 }
Exemplo n.º 2
0
 public function registerGithubUser()
 {
     if (!Session::has('github_access_token')) {
         return Response::make('Unauthorized GitHub access.', 401);
     }
     $token = Session::get('github_access_token');
     $ch = curl_init('https://api.github.com/user');
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: token {$token}"));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
     curl_setopt($ch, CURLOPT_USERAGENT, 'SWAMP');
     $response = curl_exec($ch);
     $github_user = json_decode($response, true);
     // Append email information
     //
     $ch = curl_init('https://api.github.com/user/emails');
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: token {$token}"));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
     curl_setopt($ch, CURLOPT_USERAGENT, 'SWAMP');
     $response = curl_exec($ch);
     $github_emails = json_decode($response);
     $github_user['email'] = '';
     $primary_verified = false;
     foreach ($github_emails as $email) {
         if ($email->primary == '1' && $email->verified == '1') {
             $primary_verified = true;
             $github_user['email'] = $email->email;
         } else {
             if ($email->primary == '1') {
                 $github_user['email'] = $email->email;
             }
         }
     }
     $names = array_key_exists('name', $github_user) ? explode(' ', $github_user['name']) : array('', '');
     $user = new User(array('first_name' => array_key_exists(0, $names) ? $names[0] : '', 'last_name' => array_key_exists(1, $names) ? $names[1] : '', 'preferred_name' => array_key_exists('name', $github_user) ? $github_user['name'] : '', 'username' => $github_user['login'], 'password' => md5(uniqid()) . strtoupper(md5(uniqid())), 'user_uid' => GUID::create(), 'email' => $github_user['email'], 'address' => array_key_exists('location', $github_user) ? $github_user['location'] : ''));
     // Attempt username permutations
     //
     for ($i = 1; $i < 21; $i++) {
         $errors = array();
         if ($user->isValid($errors, true)) {
             break;
         }
         if ($i == 20) {
             return Response::make('Unable to generate SWAMP GitHub user:<br/><br/>' . implode('<br/>', $errors), 401);
         }
         $user->username = $github_user['login'] . $i;
     }
     $user->add();
     $linkedAccount = new LinkedAccount(array('user_uid' => $user->user_uid, 'user_external_id' => $github_user['id'], 'linked_account_provider_code' => 'github', 'enabled_flag' => 1));
     $linkedAccount->save();
     if ($primary_verified) {
         // Mark user account email verified flag
         $userAccount = $user->getUserAccount();
         $userAccount->email_verified_flag = 1;
         $userAccount->save();
         Mail::send('emails.welcome', array('user' => $user, 'logo' => Config::get('app.cors_url') . '/images/logos/swamp-logo-small.png', 'manual' => Config::get('app.cors_url') . '/documentation/SWAMP-UserManual.pdf'), function ($message) use($user) {
             $message->to($user->email, $user->getFullName());
             $message->subject('Welcome to the Software Assurance Marketplace');
         });
         return Response::json(array('primary_verified' => true, 'user' => $user));
     } else {
         $emailVerification = new EmailVerification(array('user_uid' => $user->user_uid, 'verification_key' => GUID::create(), 'email' => $user->email));
         $emailVerification->save();
         $emailVerification->send('#register/verify-email');
         return Response::json(array('primary_verified' => false, 'user' => $user));
     }
 }
Exemplo n.º 3
0
 /**
  * user verification methods
  */
 public function getEmailVerification()
 {
     return EmailVerification::where('user_uid', '=', $this->user_uid)->first();
 }
 public function deleteIndex($verificationKey)
 {
     $emailVerification = EmailVerification::where('verification_key', '=', $verificationKey)->first();
     $emailVerification->delete();
     return $emailVerification;
 }