Exemplo n.º 1
0
 /**
  * This static function takes a supplied username and password, and returns the associated user if the combination is valid. Accepts either e-mail / password or UTwente credentials.
  *
  * @param $username The e-mail address or UTwente username.
  * @param $password The password or UTwente password.
  * @return User The user associated with the credentials, or null if no user could be found or credentials are invalid.
  */
 public static function verifyCredentials($username, $password)
 {
     // First, we try matching our own records.
     $user = User::where('email', $username)->first();
     // See if we can authenticate the user ourselves.
     if ($user && Hash::check($password, $user->password)) {
         return $user;
     } else {
         // See if someone maybe used their Proto username.
         $member = Member::where('proto_username', $username)->first();
         // Check password again.
         if ($member && $member->user && Hash::check($password, $member->user->password)) {
             return $member->user;
         } else {
             // We cannot authenticate to our own records. Try RADIUS.
             $user = User::where('utwente_username', $username)->first();
             if ($user) {
                 if (AuthController::verifyUtwenteCredentials($user->utwente_username, $password)) {
                     return $user;
                 }
             }
         }
     }
     return null;
 }
Exemplo n.º 2
0
 /**
  * Adds a member object to a user.
  *
  * @param $id
  * @return mixed
  */
 public function addMembership($id, Request $request)
 {
     $user = User::findOrFail($id);
     if (!($user->address && $user->bank)) {
         Session::flash("flash_message", "This user really needs a bank account and address. Don't bypass the system!");
         return Redirect::back();
     }
     $member = Member::create();
     $member->is_associate = !$request->input('is_primary');
     $member->user()->associate($user);
     /** Create member alias */
     $name = explode(" ", $user->name);
     $aliasbase = MemberAdminController::transliterateString(strtolower(preg_replace('/\\PL/u', '', substr($name[0], 0, 1)) . '.' . preg_replace('/\\PL/u', '', implode("", array_slice($name, 1)))));
     $alias = $aliasbase;
     $i = 0;
     while (Member::where('proto_username', $alias)->withTrashed()->count() > 0) {
         $i++;
         $alias = $aliasbase . '-' . $i;
     }
     $member->proto_username = $alias;
     /** End create member alias */
     $member->save();
     $name = $user->name;
     $email = $user->email;
     Mail::queue('emails.membership', ['user' => $user, 'internal' => config('proto.internal')], function ($m) use($name, $email) {
         $m->replyTo('*****@*****.**', config('proto.internal') . ' (Officer Internal Affairs)');
         $m->to($email, $name);
         $m->subject('Start of your membership of Study Association Proto');
     });
     Session::flash("flash_message", "Congratulations! " . $user->name . " is now our newest member!");
     return redirect()->route('user::member::list');
 }