Exemple #1
0
 /**
  * Validate and update user
  * @param Request
  * @return User
  */
 public function updateUser(Request $request)
 {
     $this->validate($request, ['username' => 'required', 'email' => 'required|email', 'role' => 'required']);
     $loggedInuser = Auth::user();
     $user = User::where('username', $request->input("username"))->first();
     $userEmailCheck = User::where("email", $request->input("email"))->first();
     if (!empty($user) && (empty($userEmailCheck) || !empty($userEmailCheck) && $user->user_id == $userEmailCheck->user_id)) {
         $user->name = $request->input("name");
         $user->username = $request->input("username");
         $user->email = $request->input("email");
         $user->role = $request->input("role");
         $user->updated_by = $loggedInuser->user_id;
         $user->save();
         $userNew = User::where('username', $user->username)->first();
         $userNew->role_desc = Roles::where('role_id', $userNew->role)->first()->role_desc;
         return $this->respondWithCORS($userNew);
     } else {
         if (!empty($user) && $user->user_id != $userEmailCheck->user_id) {
             $error = new Notification();
             $error->notify("Email already in use. Please provide different email.", 5301);
             return $this->respondWithCORS($error);
         } else {
             $error = new Notification();
             $error->notify("User not found.", 5301);
             return $this->respondWithCORS($error);
         }
     }
 }
Exemple #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Roles::create(['role_desc' => 'Admin', 'is_valid' => true, 'created_by' => 1, 'updated_by' => 1]);
     Roles::create(['role_desc' => 'Regular User', 'is_valid' => true, 'created_by' => 1, 'updated_by' => 1]);
 }
Exemple #3
0
 /**
  * Get all the roles available in the system
  * @return Roles
  */
 public function getRoles()
 {
     $roles = Roles::all();
     return $this->respondWithCORS($roles);
 }