protected function landingPage($_user_type = false) { if ($_user_type === false) { $_user_type = 0; // Try to use the current logged in user(if any) details // if (session()->has('current_user_type')) { $_user_type = session()->get('current_user_type'); } } $user_type = intval($_user_type); if ($user_type === 1) { // Admin user // TODO: add admin landing uri return url(); } else { if ($user_type === 0) { // Normal user // TODO: change this to real landing page return route('my_account', ['uid' => App\Crypt::urlencode(session()->get('current_user')->id)]); } else { return url(); } } // If all else fails.. redirect to home page }
protected function signUpConfirmation($_params = []) { $uid = intval($_params['uid']); if ($uid < 1) { xplog('Invalid user id "' . $uid . '"', __METHOD__); return false; } $data = ['fname' => $_params['fname'], 'email' => $_params['email'], 'confirmation_link' => route('signup_confirmation', ['uid' => App\Crypt::urlencode($uid)])]; return Mail::send('emails.signup_confirmation', $data, function ($m) use($_params) { $m->to($_params['email'], $_params['fname'])->subject('AuctionApp - verify your email address'); $m->from('*****@*****.**', 'AcutionApp'); }); }
public function login(Request $request) { if (Auth::check()) { // If the user is already logged in then redirect to landing page. return redirect($this->landingPage()); } $p = ['email' => '', 'password' => '']; $data = []; view()->share(['title' => 'Log In', 'CB_PAGE_JS' => [url('/js/mods/Cb.Notify.js')]]); if ($request->isMethod('post') && $request->has('submit')) { $p = $request->all(); // See: https://github.com/Respect/Validation/blob/master/docs/README.md $checks = []; $checks['email'] = Valid::email()->notEmpty()->validate($p['email']); $checks['password'] = Valid::string()->notEmpty()->validate($p['password']); try { if (in_array(false, $checks)) { throw new Exception('Some required field have invalid values'); } $auth_response = App\Cb\Users::authenticate($p['email'], $p['password']); if (!is_object($auth_response)) { if (is_numeric($auth_response)) { // $auth_response <-- is user id in this context $resend_link = route('resend_signup_confirmation', ['uid' => App\Crypt::urlencode($auth_response)]); throw new Exception('Please verify your account. Click <a href="' . $resend_link . '">here</a> to resend the confirmation email'); } throw new Exception('Invalid email or password'); } // Successfully authenticated, save some details to session for faster access // $request->session()->put('current_user', $auth_response); $request->session()->put('current_user_type', $auth_response->type); App\Cb\Users\Presence::setOnline($auth_response->id); // Set presence as online return redirect($this->landingPage($auth_response->type)); } catch (Exception $err) { cb_set_message($err->getMessage(), 0); } } $data['post'] = $p; return View::make('user_login', $data)->render(); }
protected function userAuthenticate($_post) { $p = $_post; $this->req($p, ['email', 'password', 'token', 'os']); $auth_response = App\Cb\Users::authenticate($p['email'], $p['password'], true); $uid; if (!is_object($auth_response)) { if (is_numeric($auth_response)) { // $auth_response <-- is user id in this context $resend_link = route('resend_signup_confirmation', ['uid' => App\Crypt::urlencode($auth_response)]); $uid = $auth_response; } else { $this->error('Invalid email or password'); } } else { $uid = $auth_response->id; App\Cb\Users\Presence::setOnline($uid); // Set presence as online } // Save the token for this user // App\Cb\Devices::add($uid, $p['token'], $p['os']); xplog('Registered device token "' . $p['token'] . '" for user "' . $uid . '" for os "' . $p['os'] . '"', __METHOD__); $user_details = App\Cb\Users::getDetailsById($uid); if (!$user_details) { $this->error('Unable to find user details.'); } if (isset($resend_link)) { $user_details->resend_link = $resend_link; } return ['api_name' => $_post['api_name'], 'payload' => $user_details]; }