예제 #1
0
 public function verifyCode(Request $request)
 {
     $filterColumns = ['code' => 'code'];
     $now = date('Y-m-d H:i:s', time());
     $codes = VerificationCode::filterColumns($filterColumns);
     $user = Auth::user();
     //set verifiaction time to user
     $user->mobile_verified = $now;
     $user->save();
     $codes->where('user_id', '=', $user->id)->where('active', '=', 1)->where('expiration', '>=', $now);
     if (!count($codes->get())) {
         return response()->json(['error' => 'code not found'], 404);
     } else {
         $code = $codes->get()[0];
         $code->active = 0;
         //diactivate used code
         $code->save();
         return response()->json(['status' => 'ok'], 200);
     }
 }
 /**
  * Creates a new user
  * 	Data should be POSTed to this function only
  * @return REDIRECT home
  */
 public function store()
 {
     // Only allow following fields to be submitted
     $data = Request::only(['uid', 'password', 'password_confirmation', 'student_id', 'graduation_year', 'course', 'name', 'token', 'email']);
     // Validate all input
     $validator = Validator::make($data, ['uid' => 'required|unique:users|min:5|alpha_num', 'student_id' => 'numeric|required|unique:users', 'password' => 'required|confirmed|min:5', 'graduation_year' => 'required|numeric|digits:4', 'course' => 'required', 'name' => 'required', 'email' => 'required|unique:users']);
     $importantValues = ['token' => $data['token'], 'email' => $data['email']];
     try {
         VerificationCode::where('email', $data['email'])->where('confirmation_code', $data['token'])->firstOrFail();
     } catch (ModelNotFoundException $e) {
         return Redirect::back()->withInput()->withErrors(['The verification code supplied is not valid']);
     }
     if ($validator->fails()) {
         // If validation fails, redirect back to
         // registration form with errors
         return Redirect::back()->withInput()->withErrors($validator)->withInput();
     }
     // All usernames need to be lowercase
     $data['uid'] = strtolower($data['uid']);
     $settings = $this->getLDAPDefaults();
     $entry['objectClass'][] = 'account';
     $entry['objectClass'][] = 'top';
     $entry['objectClass'][] = 'posixAccount';
     $entry['objectClass'][] = 'mailAccount';
     $entry['dn'] = 'cn=' . $data['uid'] . ',cn=' . $settings['registration_group'] . ',' . env('BASE_DN');
     $entry['gidNumber'] = $settings['registration_group_id'];
     $entry['uid'] = $data['uid'];
     // Get UID number, use it then increment it
     $current_uid_number = Setting::where('name', 'current_uid_number')->first();
     $entry['uidNumber'] = $current_uid_number->setting;
     $current_uid_number->setting++;
     $current_uid_number->save();
     $entry['userPassword'] = $data['password'] = $this->generateLDAPPassword($data['password']);
     $entry['homeDirectory'] = $settings['default_home_directory'] . $data['uid'];
     $entry['loginShell'] = $settings['default_shell'];
     $entry['cn'] = $data['uid'];
     // Email of form {username}@{Top Level Domain}
     $entry['mail'] = $data['uid'] . '@' . env('USER_DOMAIN');
     // Create new user in LDAP
     $adLDAP = new adLDAP();
     $ldapUsers = new adLDAPUsers($adLDAP);
     $ldapUsers->create($entry);
     // Create new user locally
     $newUser = User::create($data);
     // Get missing defaults from LDAP
     Auth::attempt(['uid' => $data['uid'], 'password' => $data['password']]);
     // login user
     Auth::login($newUser);
     if ($newUser) {
         // If successful, go to home
         return Redirect::route('static/ssh');
     }
     // If unsuccessful, return with errors
     return Redirect::back()->withInput()->withErrors(['message' => 'We\'re sorry but registration failed, please email ' . env('DEV_EMAIL')])->withInput();
 }