/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //get the persons details $staff = Staff::find($request->user); $data = ['email' => $staff->email]; // var_dump($data); // dd($data); $rules = ['email' => 'min:5|email|required|unique:users']; $validator = \Validator::make($data, $rules); if ($validator->passes()) { // dd($staff->id); //array to hold final permission values $array_of_permissions = Helper::prepPermissions($request->exempt_permission, 'false'); $credentials = ['email' => $staff->email, 'password' => $request->password, 'permissions' => $array_of_permissions, 'staff_id' => $staff->id, 'first_name' => $staff->fname, 'last_name' => $staff->lname]; //create new user $user = \Sentinel::create($credentials); //activate user $activation = \Activation::create($user); $activation_completed = \Activation::complete($user, $activation->code); //assign new user to role(s) $user = \Sentinel::findById($user->id); foreach ($request->assign_roles as $role_id) { $role = \Sentinel::findRoleById($role_id); $role->users()->attach($user); } return \Redirect::to('settings/users/create'); } else { return \Redirect::back()->withInput()->withErrors($validator); } }
/** * Reactivate the given user. * * @param int $id * @return \Illuminate\Http\RedirectResponse */ public function reactivate($id) { $user = Sentinel::findById($id); $activation = Activation::exists($user) ?: Activation::create($user); if (Activation::complete($user, $activation->code)) { return Redirect::route('user.edit', $id)->withSuccess(trans('users/messages.success.activate')); } return Redirect::route('user.edit', $id)->withErrors(trans('users/messages.error.activate')); }
public function run() { try { $role = \Sentinel::findRoleByName('Administrator'); $credentials = ['email' => '*****@*****.**', 'password' => 'password']; $user = \Sentinel::create($credentials); $role->users()->attach($user); $activation = \Activation::create($user); $activation_complete = \Activation::complete($user, $activation->code); } catch (\Exception $e) { } }
public function run() { try { $role = \Sentinel::getRoleRepository()->createModel()->create(['name' => 'Administrator', 'slug' => 'administrator']); $role = \Sentinel::findRoleByName('Administrator'); $role->permissions = ['superadmin' => true, 'controlpanel' => true, 'admin.users.view' => true, 'admin.users.create' => true, 'admin.users.edit' => true, 'admin.users.destroy' => true, 'admin.roles.view' => true, 'admin.roles.create' => true, 'admin.roles.edit' => true, 'admin.roles.destroy' => true]; $role->save(); $credentials = ['email' => '*****@*****.**', 'password' => 'password']; $user = \Sentinel::create($credentials); $role->users()->attach($user); $activation = \Activation::create($user); $activation_complete = \Activation::complete($user, $activation->code); } catch (\Exception $e) { } }
/** * Activate the new account * @return $this */ public function activate() { $user_id = \Request::get('UserId'); $activation_code = \Request::get('ActivationCode'); try { $user = \Sentinel::getUserRepository()->findById($user_id); if (\Activation::complete($user, $activation_code)) { return redirect('auth/login')->withErrors(array('login' => 'Your account was activated successfully.')); } else { return redirect('auth/register')->withErrors(array('register' => 'Invalid Activation Code! Please Contact Us.')); } } catch (\Exception $e) { return redirect('auth/register')->withErrors(array('register' => 'Something went wrong with activating that account.')); } }
/** * process the login submit. * * @return Response */ public function login() { $potential_user = \Pinom\Models\User::where('email', 'LIKE', \Input::has('email') ? \Input::get('email') : '')->first(); if (!is_null($potential_user) && trim($potential_user->password) == '') { //echo "isnull password!"; $user = \Sentinel::findById($potential_user->id); $password = ['password' => $potential_user->id . '.' . $potential_user->email]; $user = \Sentinel::update($user, $password); $activation = \Activation::create($user); $activation = \Activation::complete($user, $activation->code); } $credentials = ['email' => \Input::has('email') ? \Input::get('email') : '', 'password' => \Input::has('passw') ? \Input::get('passw') : '']; //echo '<pre>'; //return redirect('/'); $user = \Sentinel::authenticate($credentials); //print_R($user); if ($user = \Sentinel::check()) { return redirect('/login'); } else { return redirect('/login'); } }
/** * Execute the console command. * * @return mixed */ public function handle() { $credentials = []; if (!$this->option('email') && !$this->option('password')) { $credentials['email'] = $this->ask('Whats the users email?', null); $credentials['password'] = $this->secret('Whats the users password? (it will not be displayed)', null); } else { $credentials['email'] = $this->option('email'); $credentials['password'] = $this->option('password'); $credentials['username'] = $this->option('username'); $credentials['first_name'] = $this->option('first_name'); $credentials['last_name'] = $this->option('last_name'); } if (\Validator::make($credentials, ['email' => 'required|email', 'password' => 'required'])->passes()) { $user = \Sentinel::register($credentials); $activation = \Activation::create($user); \Activation::complete($user, $activation->code); $this->info('User created successfully and user activated.'); } else { $this->error('You did not enter a valid email address!'); } }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('users')->truncate(); //truncate roles DB::table('roles')->truncate(); //truncate role_users DB::table('role_users')->truncate(); $credentials = ['email' => '*****@*****.**', 'password' => 'come', 'first_name' => 'Umaha', 'last_name' => 'Tokula']; //create new user $user = \Sentinel::create($credentials); $activation = \Activation::create($user); $activation_completed = \Activation::complete($user, $activation->code); //create coder role $coder = Sentinel::getRoleRepository()->createModel()->create(['name' => 'Coder', 'slug' => 'coder']); //assign user this role $coder->users()->attach($user); //create principal role $principal = Sentinel::getRoleRepository()->createModel()->create(['name' => 'Principal', 'slug' => 'principal']); //assign user this role $principal->users()->attach($user); //create head teacher role $head_teacher = Sentinel::getRoleRepository()->createModel()->create(['name' => 'Class Teacher', 'slug' => 'head_teacher']); //assign user this role $head_teacher->users()->attach($user); //create billing officer role $billing_officer = Sentinel::getRoleRepository()->createModel()->create(['name' => 'Billing Officer', 'slug' => 'billing_officer']); //assign user this role $billing_officer->users()->attach($user); //create admin dept officer role $admin_dept_officer = Sentinel::getRoleRepository()->createModel()->create(['name' => 'Admin Dept Officer', 'slug' => 'admin_dept_officer']); //assign user this role $admin_dept_officer->users()->attach($user); //create accounts officer role $accounts_officer = Sentinel::getRoleRepository()->createModel()->create(['name' => 'Accounts Officer', 'slug' => 'accounts_officer']); //assign user this role $accounts_officer->users()->attach($user); }
protected function processForm($mode, $id = null) { $input = array_filter(Input::all()); $rules = ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required|unique:users']; if ($id) { $user = $this->users->createModel()->find($id); $rules['email'] .= ",email,{$user->email},email"; $messages = $this->validateUser($input, $rules); if ($messages->isEmpty()) { $this->users->update($user, $input); } } else { $messages = $this->validateUser($input, $rules); if ($messages->isEmpty()) { $user = $this->users->create($input); $code = Activation::create($user); Activation::complete($user, $code); } } if ($messages->isEmpty()) { return Redirect()->to('users'); } return Redirect()->back()->withInput()->withErrors($messages); }
public function run() { /* move all groups to roles table */ $groups = DB::select('select * from groups'); foreach ($groups as $group) { $id = $group->id; $name = $group->name; $slug = str_slug($name); if ($group->id == '1') { $permissions = array('admin' => 1); } else { $permissions = array(); } Sentinel::getRoleRepository()->createModel()->create(['id' => $id, 'name' => $name, 'slug' => $slug, 'permissions' => $permissions]); } /* move users_groups data into role_users table */ $users_groups = DB::select('select * from users_groups'); foreach ($users_groups as $user_group) { $user = Sentinel::findById($user_group->user_id); $group = DB::table('groups')->where('id', '=', $user_group->group_id)->first(); $role_current = DB::table('roles')->where('name', '=', $group->name)->first(); $role = Sentinel::findRoleById($role_current->id); $role->users()->attach($user); } $this->command->info('groups, users_groups successfully migrated to roles, role_users tables'); /* insert each user into activations table */ $users = DB::select('select * from users'); foreach ($users as $user) { $current_user = Sentinel::findById($user->id); $activation = Activation::create($current_user); if ($user->activated) { Activation::complete($current_user, $activation->code); } } $this->command->info('activations created successfully'); }
Route::group(['middleware' => ['authno']], function () { Route::get('login', 'UserController@showLogin')->name('login'); Route::post('login', 'UserController@postLogin')->name('login.post'); Route::get('register', 'UserController@showRegister')->name('register'); Route::post('register', 'UserController@postRegister')->name('register.post'); }); # Admin User Section Route::group(['middleware' => ['admin']], function () { Route::get('admin/dashboard', 'AdminController@dashboard')->name('dashboard'); Route::post('showunits', 'AdminController@showUnits')->name('units.show'); Route::resource('product', 'ProductController'); // Route::get('admin/product', 'AdminController@productPage')->name('product'); // Route::post('admin/product', 'AdminController@addProduct')->name('product.post'); }); # Authenticated User Section Route::group(['middleware' => ['auth']], function () { Route::get('logout', 'UserController@logout')->name('logout'); Route::post('cart/drop', 'HomeController@cartDrop')->name('cart.drop'); Route::post('address', 'HomeController@addAddress')->name('address.add'); Route::group(['namespace' => 'user'], function () { Route::resource('basket', 'BasketController'); Route::resource('order', 'OrderController'); }); }); Route::get('activate/{id}/{code}', function ($id, $code) { $user = Sentinel::findById($id); if (!Activation::complete($user, $code)) { return Redirect()->to("login")->withErrors('Invalid or expired activation code.'); } return Redirect()->to('login')->withSuccess('Account activated.'); });
/** * User account activation page. * * @param number $userId * @param string $activationCode * @return */ public function getActivate($userId, $activationCode = null) { // Is user logged in? if (Sentinel::check()) { return Redirect::route('dashboard'); } $user = Sentinel::findById($userId); $activation = Activation::create($user); if (Activation::complete($user, $activation->code)) { // Activation was successful // Redirect to the login page return Redirect::route('signin')->with('success', Lang::get('auth/message.activate.success')); } else { // Activation not found or not completed. $error = Lang::get('auth/message.activate.error'); return Redirect::route('signin')->with('error', $error); } }
/** * @param $id * @param $code * @return $this|\Illuminate\Http\RedirectResponse */ public function getReactivate($id, $code) { if (!($user = Sentinel::check())) { return Redirect::to('login'); } $activation = Activation::exists($user) ?: Activation::create($user); // This is used for the demo, usually you would want // to activate the account through the link you // receive in the activation email Activation::complete($user, $activation->code); $code = $activation->code; $sent = Mail::send('emails.activate', compact('user', 'code'), function ($m) use($user) { $m->to($user->email)->subject('Activate Your Account'); }); if ($sent === 0) { return Redirect::to('login')->withErrors('Failed to send activation email.'); } return Redirect::to('account')->withSuccess('Account activated.'); }
Route::get('activate/{id}/{code}', function ($id, $code) { $user = Sentinel::findById($id); if (!Activation::complete($user, $code)) { return Redirect::to("login")->withErrors('Invalid or expired activation code.'); } return Redirect::to('login')->withSuccess('Account activated.'); })->where('id', '\\d+'); Route::get('reactivate', function () { if (!($user = Sentinel::check())) { return Redirect::to('login'); } $activation = Activation::exists($user) ?: Activation::create($user); // This is used for the demo, usually you would want // to activate the account through the link you // receive in the activation email Activation::complete($user, $activation->code); // $code = $activation->code; // $sent = Mail::send('sentinel.emails.activate', compact('user', 'code'), function($m) use ($user) // { // $m->to($user->email)->subject('Activate Your Account'); // }); // if ($sent === 0) // { // return Redirect::to('register') // ->withErrors('Failed to send activation email.'); // } return Redirect::to('account')->withSuccess('Account activated.'); })->where('id', '\\d+'); Route::get('deactivate', function () { $user = Sentinel::check(); Activation::remove($user);
/** * Processes the form. * * @param string $mode * @param int $id * @return \Illuminate\Http\RedirectResponse */ protected function processForm($mode, $id = null) { $rules = ['email' => 'required|unique:users', 'password' => 'sometimes|required', 'password_confirm' => 'required_with:password|same:password']; if ($id) { $user = $this->users->createModel()->find($id); $rules['email'] .= ",email,{$user->email},email"; $input = $this->prepareInput(Input::all(), $mode === 'update' ? true : false); $messages = $this->validateUser($input, $rules); if ($messages->isEmpty()) { try { // Update the user $this->users->update($user, array_except($input, 'roles')); // Get the new user roles $roles = array_get($input, 'roles', []); // Get the user roles $userRoles = $user->roles->lists('id'); // Prepare the roles to be added and removed $toAdd = array_diff($roles, $userRoles); $toDel = array_diff($userRoles, $roles); // Detach the user roles if (!empty($toDel)) { $user->roles()->detach($toDel); } // Attach the user roles if (!empty($toAdd)) { $user->roles()->attach($toAdd); } } catch (NotUniquePasswordException $e) { return Redirect::back()->withInput()->withErrors('This password was used before. You must choose a unique password.'); } } } else { $input = $this->prepareInput(Input::all(), true); $messages = $this->validateUser($input, $rules); if ($messages->isEmpty()) { $user = $this->users->create($input); $activation = Activation::create($user); Activation::complete($user, $activation->code); } } if ($messages->isEmpty()) { return Redirect::route('users.index')->withSuccess(trans("users/messages.success.{$mode}")); } return Redirect::back()->withInput()->withErrors($messages); }
protected function createAdminUserAndRole() { try { $role = \Sentinel::getRoleRepository()->createModel()->create(['name' => 'Administrator', 'slug' => 'administrator']); $role = \Sentinel::findRoleByName('Administrator'); $role->permissions = ['superadmin' => true, 'controlpanel' => true, 'admin.users.view' => true, 'admin.users.create' => true, 'admin.users.edit' => true, 'admin.users.destroy' => true, 'admin.roles.view' => true, 'admin.roles.create' => true, 'admin.roles.edit' => true, 'admin.roles.destroy' => true]; $role->save(); $credentials = ['email' => '*****@*****.**', 'password' => 'password']; $user = \Sentinel::create($credentials); $role->users()->attach($user); $activation = \Activation::create($user); $activation_complete = \Activation::complete($user, $activation->code); $this->info('Admin Role and User created successfully.'); } catch (\Exception $e) { $this->info('Something went wrong while creating Admin Role and User.'); } }
protected function createAdminUserAndRole() { $permissions = ['superadmin' => ['default' => true, 'description' => 'Super Admin'], 'controlpanel' => ['default' => true, 'description' => 'Access to the Control Panel'], 'admin.users.view' => ['default' => true, 'description' => 'View Users'], 'admin.users.create' => ['default' => true, 'description' => 'Create Users'], 'admin.users.edit' => ['default' => true, 'description' => 'Edit Users'], 'admin.users.destroy' => ['default' => true, 'description' => 'Delete Users'], 'admin.roles.view' => ['default' => true, 'description' => 'View Roles'], 'admin.roles.create' => ['default' => true, 'description' => 'Create Roles'], 'admin.roles.edit' => ['default' => true, 'description' => 'Edit Roles'], 'admin.roles.destroy' => ['default' => true, 'description' => 'Delete Roles'], 'admin.permissions.view' => ['default' => true, 'description' => 'View Permissions'], 'admin.permissions.create' => ['default' => true, 'description' => 'Create Permissions'], 'admin.permissions.edit' => ['default' => true, 'description' => 'Edit Permissions'], 'admin.permissions.destroy' => ['default' => true, 'description' => 'Delete Permissions']]; try { //create admin user $credentials = ['email' => '*****@*****.**', 'password' => 'password']; $user = \Sentinel::create($credentials); $activation = \Activation::create($user); $activation_complete = \Activation::complete($user, $activation->code); //create admin role $role = \Sentinel::getRoleRepository()->createModel()->create(['name' => 'Administrator', 'slug' => 'administrator']); $role = \Sentinel::findRoleByName('Administrator'); //add permissions to role foreach ($permissions as $key => $permission) { $role->addPermission($key, $permission['default']); } $role->save(); //attach admin user to admin role $role->users()->attach($user); $this->info('Admin Role and User created successfully.'); $this->addPermissions($permissions); } catch (\Exception $e) { $this->info('Something went wrong while creating Admin Role and User.'); $this->error($e); } }