public function run()
 {
     $user = User::where('email', '*****@*****.**')->first();
     if (!$user) {
         $user = User::Create(['name' => 'administrator', 'email' => '*****@*****.**', 'password' => bcrypt('admin'), 'is_admin' => true]);
     }
 }
Example #2
0
 /**
  * Boot the authentication services for the application.
  *
  * @return void
  */
 public function boot()
 {
     // Here you may define how you wish users to be authenticated for your Lumen
     // application. The callback which receives the incoming request instance
     // should return either a User instance or null. You're free to obtain
     // the User instance via an API token or any other method necessary.
     $this->app['auth']->viaRequest('token', function (Request $request) {
         if ($request->header('apitoken')) {
             return User::where('api_token', $request->header('apitoken'))->first();
         }
     });
 }
Example #3
0
 /**
  * Validate and Send email to user
  * @param Request
  * @return Notification
  */
 public function forgotPassword(Request $request)
 {
     $this->validate($request, ['username' => 'required']);
     $user = User::where('email', $request->input("username"))->orWhere('username', $request->input("username"))->first();
     if (!empty($user)) {
         // @todo email implementation goes here
         $success = new Notification();
         $success->notify("We have sent an email to your registered email. Please follow the steps to reset your password.", 5200, "success");
         return $this->respondWithCORS($success);
     } else {
         $error = new Notification();
         $error->notify("User not found.", 5200);
         return $this->respondWithCORS($error);
     }
 }
Example #4
0
 /**
  * validateLogin validates the username/email and password from database.
  * @param Request
  * @return Notification
  */
 public function validateLogin(Request $request)
 {
     $emailLogin = ['email' => $request->input("username"), 'password' => hash('sha1', $request->input("password"))];
     $usernameLogin = ['username' => $request->input("username"), 'password' => hash('sha1', $request->input("password"))];
     $user = User::where($emailLogin)->orWhere($usernameLogin)->first();
     if (!empty($user)) {
         $salt = new Salt();
         $user->api_token = hash('sha1', $salt->spiceItUp($user->email));
         $user->save();
         return $user;
     } else {
         $error = new Notification();
         $error->notify("Provided Username and Password doesn't match. Please try again.", 5000);
         return $error;
     }
 }
Example #5
0
 /**
  * Delete the user by user_id
  * @param User
  * @return Notification
  */
 public function deleteUser($user_id)
 {
     $user = User::where('user_id', $user_id)->first();
     if (!empty($user)) {
         $user->delete();
         $success = new Notification();
         $success->notify("User deleted.", 5102, "success");
         return $this->respondWithCORS($success);
     } else {
         $error = new Notification();
         $error->notify("User not found.", 5103);
         return $this->respondWithCORS($error);
     }
 }
Example #6
0
 /**
  * index method gets logged in user from Auth:user and returns a json object.
  * @param void
  * @return loggedInUser
  */
 public function index()
 {
     $loggedInuser = Auth::user();
     $user = User::where("user_id", $loggedInuser->user_id)->first();
     return $this->respondWithCORS($user);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function edit($id)
 {
     try {
         $model = $this->getModel($id);
         $roles = Role::lists('name', 'id');
         $model_roles = $model->roles->lists('id');
         $departments = Department::lists('name', 'id');
         $model_departments = $model->departments->lists('id');
         $users = User::where('id', '<>', $id)->withTrashed()->lists('display_name', 'id');
         return view($this->edit_view, compact(['model', 'roles', 'model_roles', 'departments', 'model_departments', 'users']));
     } catch (Exception $e) {
         Flash::warning(trans($this->resource_name . 'not_found', ['model' => $this->model_name, 'id' => $id]));
         return $this->index();
     }
 }
Example #8
0
 public function listUsers()
 {
     $ex = User::join('role_user', 'users.id', '=', 'role_user.user_id')->join('roles', 'role_user.role_id', '=', 'roles.id')->where('role_title', '=', 'Cliente')->where('active', '=', '1')->has('clientes', '<', 1)->get(['users.*'])->lists('username', 'id')->toArray();
     $ac = User::where('id', '=', $this->user_id)->lists('username', 'id')->toArray();
     return $ex + $ac;
 }