/** * Run the database seeds. * * @return void */ public function run() { User::create(['name' => 'test', 'email' => '*****@*****.**', 'password' => bcrypt('secret'), 'role' => 'user']); User::create(['name' => 'testAdmin', 'email' => '*****@*****.**', 'password' => bcrypt('secret'), 'role' => 'admin']); factory(User::class, 10)->create(); factory(User::class, 'admin', 2)->create(); }
/** * Run the database seeds. * * @return void */ public function run() { factory(Post::class, 50)->create()->each(function ($item) { $users = User::all()->random(random_int(1, 10))->all(); foreach ($users as $user) { $item->likes()->create(['user_id' => $user->id]); } }); }
/** * Process request to create user * @param App\Http\Requests\Auth\UserCreation $request * @param App\Storage\EmailConfirmation\EmailConfirmationRepository $tokens * @return Illuminate\Http\RedirectResponse */ public function postCreate(UserCreation $request) { $valid = $this->tokens->verify($request->email, $request->token); if (!$valid) { return redirect()->route('home')->withDanger(trans('auth.token_not_valid')); } User::create(['email' => $request->email, 'username' => $request->username, 'password' => bcrypt($request->password)]); $this->tokens->delete($request->email); return redirect()->route('auth.signin')->withSuccess("User {$request->username} was created. You can now sign in."); }
/** * Process request to reset password * * @param App\Http\Requests\Auth\PasswordReset $request * @return Illuminate\Http\RedirectResponse */ public function patchReset(PasswordReset $request) { $valid = $this->tokens->verify($request->email, $request->token); if (!$valid) { return redirect()->route('home')->withDanger(trans('auth.token_not_valid')); } User::where('email', $request->email)->update(['password' => bcrypt($request->password)]); $this->tokens->delete($request->email); return redirect()->route('auth.signin')->withSuccess("Password was changed successfully."); }
public function findOrCreateUser($data) { $user = User::where('email', $data->email)->first(); if ($user) { $user->google_id = $data->id; $user->name = $data->name; $user->save(); } else { $user = User::create(['email' => $data->email, 'name' => $data->name, 'username' => str_random(5) . time(), 'password' => bcrypt(str_random(10)), 'google_id' => $data->id]); } return $user; }
public function authenticate(Request $request) { $user = User::where('email', $request->email)->first(); if (!$user) { throw new BadRequestHttpException('Invalid credentials'); } $customClaims = ['name' => $user->name, 'email' => $user->email, 'role' => $user->role, 'gravatar' => $user->gravatar]; $token = JWTAuth::attempt($request->only('email', 'password'), $customClaims); if (!$token) { throw new BadRequestHttpException('Invalid credentials'); } return api_response(200, compact('token')); }
/** * Run the database seeds. * * @return void */ public function run() { if (App::environment() === 'production') { die('Database seeding should not be run on a production server.'); } //Truncate the user table before each seed, to be a bit more efficient. User::truncate(); //Disable mass assignment rules in the Eloquent model, need to be able to add all fields here. Model::unguard(); //Calls the model factory and creates and stores objects corresponding to the specified class. factory(User::class, 100)->create(); //Re-enables mass assignment rules. Model::reguard(); }
public function findOrCreateUser($data) { $user = User::where('facebook_id', $data->id)->first(); if ($user) { $user->email = $data->email; $user->name = $data->first_name . ' ' . $data->last_name; $user->save(); return $user; } $user = User::where('email', $data->email)->first(); if ($user) { $user->facebook_id = $data->id; $user->name = $data->first_name . ' ' . $data->last_name; $user->save(); return $user; } return User::create(['email' => $data->email, 'name' => $data->first_name . ' ' . $data->last_name, 'password' => bcrypt(str_random(10)), 'facebook_id' => $data->id]); }
public function isNot(User $user) { return $this->getKey() != $user->getKey(); }
/** * Bootstraps */ public function boot() { User::observe(new \App\Observers\Validation\UserValidationObserver(\App::make('validator'))); }
public function test() { User::create(['email' => self::EMAIL, 'username' => self::USERNAME, 'password' => bcrypt(self::PASSWORD)]); $this->visit('/signin')->submitForm('Sign in', ['user' => self::EMAIL, 'password' => self::PASSWORD, 'remember-not' => true])->seePageIs('/')->dontSee('Could not sign you in')->visit('/logout')->see('Bye bye')->visit('/signin')->submitForm('Sign in', ['user' => self::USERNAME, 'password' => self::PASSWORD, 'remember-not' => true])->seePageIs('/')->dontSee('Could not sign you in'); }
/** * Initializes context. * * Every scenario gets its own context instance. * You can also pass arbitrary arguments to the * context constructor through behat.yml. */ public function __construct() { User::boot(); }