예제 #1
0
 /**
  * [auth description]
  * @param  [type] $user_id   [user_id from pragyanV3_users table]
  * @param  [type] $user_pass [user_password from pragyanV3_users table for db auth,webmail pass otherwise]
  * @return [type] Boolean    [true if authenticated, false if not]
  */
 public static function auth($user_id, $user_pass)
 {
     $existing_user = User::where('user_id', $user_id)->get();
     if (count($existing_user) == 0) {
         return false;
     }
     $loginmethod = $existing_user[0]->user_loginmethod;
     $activated = $existing_user[0]->user_activated;
     $db_user_pass = $existing_user[0]->user_password;
     // $user_roll   	= $existing_user[0]->user_name; // Is roll number for NITT students
     if ($activated == 0) {
         return false;
     }
     // IMAP login for NITT Students
     if ($loginmethod === "imap") {
         $user_roll = explode("@", $existing_user[0]->user_email)[0];
         if (!IMAPAuth::nittauth($user_roll, $user_pass)) {
             return false;
         } else {
             return true;
         }
     }
     // DB login for non-NITT
     if ($loginmethod === "db") {
         // DB login
         if ($existing_user[0]->user_password === md5($user_pass)) {
             return true;
         } else {
             return false;
         }
     }
 }
 public function login(Request $request)
 {
     $user_roll = $request->input('user_roll');
     $user_pass = $request->input('user_pass');
     $ldap_auth = LDAPAuth::auth($user_roll, $user_pass);
     $imap_auth = IMAPAuth::auth($user_roll, $user_pass);
     if ($ldap_auth || $imap_auth) {
         $user = User::where('user_roll', '=', $user_roll)->first();
         if ($user == NULL) {
             return JSONResponse::response(400);
         }
         $generated_secret = sha1($user->user_roll . "Pragyan16Rocks");
         $user->user_secret = $generated_secret;
         $user->save();
         return JSONResponse::response(200, $generated_secret);
     } else {
         return JSONResponse::response(401);
     }
 }