/** * 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) { } }
/** * Register an account * * @param AccountRegister $request * * @return $this */ public function Register(AccountRegister $request) { try { $credentials = array('username' => \Input::get('username'), 'email' => \Input::get('email'), 'password' => \Input::get('password')); \Sentinel::register($credentials); $activation_user = \Sentinel::getUserRepository()->findByCredentials($credentials); $activation = \Activation::create($activation_user); \Mail::queue('emails.account.activate_account', ['username' => \Input::get('username'), 'user_id' => $activation['user_id'], 'activation_code' => $activation['code'], 'activation_url' => env('URL') . '/auth/activate?' . http_build_query(array('ActivationCode' => $activation['code'], 'UserId' => $activation['user_id']))], function ($message) { $message->from('*****@*****.**', 'Modest Music | Account Services'); $message->to(\Input::get('email')); }); return redirect('auth/login')->withErrors(array('login' => 'We have sent your activation email. Please check the Spam Folder.')); } catch (\Exception $e) { return redirect('auth/register')->withErrors(array('register' => $e->getMessage())); } }
/** * Handle posting of the form for the user registration. * * @return \Illuminate\Http\RedirectResponse */ public function processRegistration() { $input = Input::all(); $rules = ['email' => 'required|email|unique:users', 'password' => 'required', 'password_confirm' => 'required|same:password']; $validator = Validator::make($input, $rules); if ($validator->fails()) { return Redirect::back()->withInput()->withErrors($validator); } if ($user = Sentinel::register($input)) { $activation = Activation::create($user); $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('login')->withSuccess('Your accout was successfully created. You might login now.')->with('userId', $user->getUserId()); } return Redirect::to('register')->withInput()->withErrors('Failed to register.'); }
/** * 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!'); } }
/** * 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'); } }
/** * 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'); }
public function activate_account_from_email(FunctionalTester $I) { $I->am('Unlogged user with a not activated account'); $I->wantTo('activate my account'); $I->expectTo('see a success confirmation message explaining that my account is activated'); /*************************************************************************************************************** * settings **************************************************************************************************************/ // we create a user $this->_credentials = ['last_name' => 'NOM', 'first_name' => 'Prénom', 'email' => '*****@*****.**', 'password' => 'password']; $user = \Sentinel::register($this->_credentials); // we create an activation $activation = \Activation::create($user); /*************************************************************************************************************** * run test **************************************************************************************************************/ $I->sendAjaxRequest('GET', route('account.activate', ['email' => $user->email, 'token' => $activation->code])); $I->see(trans('global.modal.alert.title.success')); $I->see(strip_tags(trans('auth.message.activation.success', ['name' => $user->first_name . ' ' . $user->last_name]))); }
/** * 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); } }
if (User::getByUsernameEmailCount($username, $email) > 0) { throw new Exception('That username or email already exists. If you have forgotten your password, please use the resend password link'); } // if we get here, we can add the user. $password = getPassword(); $a = new Activation(); $a->username = $username; $a->email = $email; $a->password = md5($password); $a->nation = $nation; $a->IP = $_SERVER['REMOTE_ADDR']; $a->referrerId = $t->referrerId; $a->time = time(); $id = $a->create(); if ($id) { // Can send the email $et = new Template('activation-email', 1); $et->username = $username; $et->password = $password; $text = $et->getContents('activation-email-text'); $html = $et->getContents('activation-email-html'); $e = new Email($email, "Welome to WWII::Game $username", $html, $text); if (!$e->send()) { throw new Exception('Could not send the activation email. Please contact an admin on the forum, or by email'); }
/** * @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.'); }
<?php return array('view' => array('list' => function (array $row) { }, 'form' => function (array $row) { // empty if create form $isActive = false; if ($row) { $user = \Sentinel::findById($row['id']); $isActive = \Activation::completed($user); } return view('jarboe.c.users::patterns.user_activation', compact('isActive')); }), 'handle' => array('insert' => function ($idRow, $patternValue, $values) { if ($patternValue == 'deactivate') { return; } $user = \Sentinel::findById($idRow); $activation = \Activation::create($user); \Activation::complete($user, $activation->code); }, 'update' => function ($idRow, $patternValue, $values) { $user = \Sentinel::findById($idRow); $activation = \Activation::completed($user); if (!$activation && $patternValue == 'deactivate') { return; } elseif ($activation && $patternValue == 'deactivate') { \Activation::remove($user); } elseif (!$activation && $patternValue == 'activate') { $activation = \Activation::create($user); \Activation::complete($user, $activation->code); } }, 'delete' => function ($idRow) { }));
public function activate() { global $database; $error = array(); $activate = new Activation(); $input = $_REQUEST; if (isset($_POST["contact_name"])) { if ($_POST['contact_name'] != "") { $activate->contact_name = $_POST['contact_name']; } else { array_push($error, "Contact Name"); } } else { array_push($error, "Contact Name"); } if (isset($_POST["terminal_id"])) { if ($_POST['terminal_id'] != "") { $activate->contact_name = $_POST['terminal_id']; } else { array_push($error, "Terminal ID"); } } else { array_push($error, "Terminal ID"); } if (empty($error)) { $cproduct = Cproduct::find_by_terminal($_POST['terminal_id']); if ($cproduct) { $cproduct->client_id = $_SESSION["client_ident"]; //$cproduct->client_name = $_POST["clientname"]; $cproduct->terminal_id = $_POST['terminal_id']; $cproduct->prod_name = $_POST['product_name']; $cproduct->branch = $_POST['branch']; $cproduct->atm_type = $_POST['atm_type']; $cproduct->install_status = 1; $cproduct->status = 1; $cproduct->client_id = $_SESSION['client_ident']; $cproduct->install_city = $_POST['city']; $cproduct->install_address = $_POST['location']; $cproduct->install_state = $_POST['state']; $cproduct->update(); } else { $cproduct = new Cproduct(); $cproduct->client_id = $_SESSION["client_ident"]; //$cproduct->client_name = $_POST["clientname"]; $cproduct->terminal_id = $_POST['terminal_id']; $cproduct->prod_name = $_POST['product_name']; $cproduct->branch = $_POST['branch']; $cproduct->atm_type = $_POST['atm_type']; $cproduct->install_status = 1; $cproduct->status = 1; $cproduct->datecreated = date("Y-m-d H:i:s"); $cproduct->install_city = $_POST['city']; $cproduct->install_address = $_POST['location']; $cproduct->install_state = $_POST['state']; $cproduct->create(); } if (!empty($input)) { foreach ($input as $key => $value) { $activate->{$key} = $value; } $activate->client_id = $_SESSION['client_ident']; $activate->prod_id = $cproduct->id; $activate->created_at = date("Y-m-d H:i:s"); $activate->updated_at = date("Y-m-d H:i:s"); } if ($activate->create()) { return 1; //returns 1 on success } else { return 2; //unexpected Error } } else { /* $message = "Please check the following errors: "; $lenght = count($error); for($i = 0; $i < $lenght; $i++){ $message = $message.$error[$i].", "; } echo "<div data-alert class='alert-box error'><a href='#' class='close'>×</a>$message</div>";*/ return 3; } }
include_once 'smarty/Smarty.class.php'; include_once 'classes/registration.class.php'; include_once 'classes/activation.class.php'; $smarty = new Smarty(); $smarty->template_dir = 'templates/'; $smarty->compile_dir = 'smarty/templates_c/'; $smarty->config_dir = 'smarty/configs/'; $smarty->cache_dir = 'smarty/cache/'; if (!array_key_exists('send', $_POST) == 1) { $smarty->display('registration.tpl'); } else { $registration = new Registration(); if ($registration->register()) { // Tworzy aktywację $registration->commit(); $activation = Activation::create($registration->user_id); // Wysyłanie email'a $content = 'Witaj ' . $_POST['first_name'] . '. Kliknij w link aby zakończyć proces rejestracji: zs1.jastrzebie.pl/uczen/banas/activate.php?code=' . $activation->code; $headers = 'MIME-Version: 1.0' . '\\r\\n'; $headers .= 'Content-type: text/html; charset=utf-8' . '\\r\\n'; if (!mail($_POST['email'], 'Potwierdzenie rejestracji', $content, $headers)) { throw new Exception('Wystąpił błąd. Email aktywacyjny nie został wysłany.'); } $smarty->assign('notification', 'Rejestracja powiodła się. W ciagu 24 godzin otrzymasz email aktywacyjny.'); $smarty->display('registration.tpl'); } else { $smarty->assign('notice', $registration->GetErrors()); $smarty->display('registration.tpl'); } }
//Route::get('auth/social', Route::get('wait', function () { return View::make('sentinel.wait'); }); 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.');
/** * 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() { $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); } }
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.'); } }