public static function deactivate($userId) { $a = new Activation($userId); $a->select($userId, 'user'); $a->active = 0; $a->update(); }
/** * Deactivate an activation * * @param Activation $activation * * @return bool */ public function deactivate($activation) { // set active to 0 $activation->set_activation_active(0); // persists activation $activation = license_wp()->service('activation_repository')->persist($activation); // return true of active is set to 0 return $activation->get_activation_active() == 0; }
public function process($parameters) { $activation = new Activation(); $key = $parameters[0]; $result = $activation->checkKeyReturnEmail($key); if ($result['s'] == 'success') { $result = $activation->activateUser($result['email']); } $this->messages[] = $result; $this->header['title'] = ['cs' => 'Aktivace účtu', 'en' => 'Account activation']; $this->view = 'login'; }
public function sendActivationMail($user) { $activation = new Activation(); $activation->setSfGuardUser($user); $key = sha1($user->getUsername() . time()); $activation->setActivationKey($key); $activation->save(); $message = $this->getMailer()->composeAndSend('*****@*****.**', $user->getEmailAddress(), 'Please confirm your registration!', 'Hello ' . $user->getName() . ', Please click on the following link to complete your registration: ' . $this->generateUrl('register_activation', array('activation_key' => $activation->getActivationKey()), true) . ' We hope you will have fun!'); $this->getUser()->setFlash('notice', 'Un mail de confirmation vous a été envoyé !'); $this->redirect('@homepage'); }
public function process($parameters) { $activation = new Activation(); $csfr = new Csrf(); $userId = $parameters[0]; if (!$activation->checkIfIsAdminOfUser($_SESSION['id_user'], $userId)) { $this->redirect('error'); } if (isset($_POST['sent'])) { if (!Csrf::validateCsrfRequest($_POST['csrf'])) { $this->messages[] = ['s' => 'error', 'cs' => 'Možný CSRF útok! Zkuste prosím aktivaci znovu', 'en' => 'Possible CSRF attack! Please try activation again']; $this->redirect('error'); } $tariffId = $activation->sanitize($_POST['tariff']); $startDate = $activation->sanitize($_POST['startDate']); $result = $activation->validateForceActivationData($tariffId, $startDate); if ($result['s'] == 'success') { $result = $activation->forceActivateUser($activation->getUserEmailFromId($userId), $tariffId, $startDate); } $this->messages[] = $result; if ($result['s'] == 'success') { $this->redirect('payments/' . $userId); } } $this->data['csrf'] = $csfr->getCsrfToken(); $this->data['tariffs'] = $activation->returnTariffsData($this->language); $this->header['title'] = ['cs' => 'Aktivace uživatele', 'en' => 'User activation']; $this->view = 'forceActivation'; }
/** * 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); } }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->line('Cleaning activations and reminders tables from expired lines ...'); \Activation::removeExpired(); $this->info('✔ Activations table cleaned.'); \Reminder::removeExpired(); $this->info('✔ Reminders table cleaned.'); }
public function process($parameters) { $deactivation = new Activation(); $userId = $parameters[0]; if (!$deactivation->checkIfIsAdminOfUser($_SESSION['id_user'], $userId)) { $this->redirect('error'); } $csrfToken = $parameters[1]; if (!Csrf::validateCsrfRequest($csrfToken)) { $this->messages[] = ['s' => 'error', 'cs' => 'Možný CSRF útok! Zkuste prosím deaktivaci znovu', 'en' => 'Possible CSRF attack! Please try deactivation again']; } else { $email = $deactivation->getUserEmailFromId($userId); $result = $deactivation->deactivateUser($email); $this->messages[] = $result; } $this->redirect('checkUsers'); }
public static function checkRegistration() { $rules = ['email' => FILTER_SANITIZE_SPECIAL_CHARS, 'key' => FILTER_SANITIZE_STRING]; $data = filter_input_array(INPUT_GET, $rules); $mail = urldecode($data['email']); $activation_key = urldecode($data['key']); return Activation::checkActivationCode($mail, $activation_key); }
/** * Persist activation data in WordPress database * * @param Activation $activation * * @return Activation */ public function persist($activation) { global $wpdb; // dem defaults $defaults = array('license_key' => '', 'api_product_id' => 0, 'instance' => '', 'activation_date' => '', 'activation_active' => 0); // setup array with data $data = wp_parse_args(array('license_key' => $activation->get_license_key(), 'api_product_id' => $activation->get_api_product_id(), 'instance' => $activation->get_instance(), 'activation_date' => $activation->get_activation_date()->format('Y-m-d'), 'activation_active' => $activation->get_activation_active()), $defaults); // check if new license or existing if (0 === $activation->get_id()) { // insert // insert into WordPress database $wpdb->insert($wpdb->lwp_activations, $data); // set activation id $activation->set_id($wpdb->insert_id); } else { // update // update database $wpdb->update($wpdb->lwp_activations, $data, array('activation_id' => $activation->get_id())); } return $activation; }
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.')); } }
/** * 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 activationdetails($id) { $this->view->activation = Activation::find_by_id($id); $this->view->render("support/activationdetails"); }
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.'); });
<?php require __DIR__ . '/core/initialize.php'; class Activation extends \PageHelper { public function run() { global $request; $em = \Shared\DoctrineHelper::getEntityManager(); $idAccount = \Encryption::decrypt($request->query->get("id")); if ($idAccount !== null) { $objAccount = Account\AccountHelper::getAccountRepository()->find($idAccount); if ($objAccount !== null) { if ($objAccount->getStatus() != StatusHelper::BANNI) { $objAccount->setStatus(StatusHelper::ACTIF); $em->persist($objAccount); $em->flush(); header("LOCATION: index.php?ok"); } else { echo "Ahah ! Niqué gros !"; } } else { echo "Nous n'avons pas trouvé votre compte sur nos serveurs."; } } } } $class = new Activation(); $class->run();
public function deactivate() { $user = Sentinel::check(); Activation::remove($user); return Redirect::back()->withSuccess('Account deactivated.'); }
/** * 动作:激活账号 * @param string $activationCode 激活令牌 * @return Response */ public function getActivate($activationCode) { // 数据库验证令牌 $activation = Activation::where('token', $activationCode)->first(); // 数据库中无令牌,抛出404 is_null($activation) and App::abort(404); // 数据库中有令牌 // 激活对应用户 $user = User::where('email', $activation->email)->first(); $user->activated_at = new Carbon(); $user->save(); // 删除令牌 $activation->delete(); // 激活成功提示 return View::make('authority.activationSuccess'); }
if (!$apassword) { throw new Exception('No Activation password specified'); } if (!$password1 or $password1 != $password2) { throw new Exception('The new passwords you entered do not match'); } $apassword = md5($apassword); $password1 = md5($password1); if ($filtered['activation-id']) { $aAccount->get($filtered['activation-id']); } else { $aAccount = Activation::getByUsernamePassword($username, $apassword); } if (!$aAccount->id) { throw new Exception('That account does not exist'); } if ($aAccount->success) { header('Location: index.php?e=2'); exit; } // If we get this far, the account needs to be activated, // and the user provided everything we need. $user = new User(); $user->username = $aAccount->username;
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]))); }
if (isset($_POST['register-captcha'])) { $inputValue[4] = ""; /* we need to always clear the captcha field, because it will regenerate after a reresh*/ if ($Error->captcha($_POST['register-captcha'])) { $errorClass[4] = 'success'; } else { $errorClass[4] = 'error'; } } else { if (isset($_POST['action'])) { $Error->add('error', 'Captcha cannot be left empty'); $errorClass[4] = 'error'; } } // Instantiontiate the erroring before we need to refresh the page $msg = $Error->alert(); // Check if the form was submitted without any errors. if (isset($_POST['register-username']) && isset($_POST['register-password']) && isset($_POST['register-confirm']) && isset($_POST['register-email']) && isset($_POST['register-captcha']) && !$Error->ok()) { $complete = true; // Create the actual user Auth::createNewUser($_POST['register-username'], $_POST['register-password'], $_POST['register-email']); $userId = Auth::userId($_POST['register-username']); $link = full_url_to_script('activate.php') . "?action=activate&code=" . Activation::get($userId) . "&id=" . $userId; //echo $link; Emailtemplate::setBaseDir('./assets/email_templates'); $html = Emailtemplate::loadTemplate('activation', array('title' => 'Activation Email', 'prettyName' => Options::get('prettyName'), 'name' => $_POST['register-username'], 'siteName' => Options::get('emailName'), 'activationLink' => $link, 'footerLink' => Options::get('siteName'), 'footerEmail' => Options::get('emailInfo'))); send_html_mail(array($_POST['register-username'] => $_POST['register-email']), 'Activation Email', $html, array(Options::get('siteName') => Options::get('emailAdmin'))); } Template::setBaseDir('./assets/tmpl'); $html = Template::loadTemplate('layout', array('header' => Template::loadTemplate('header', array('title' => $title, 'user' => $user, 'admin' => $isadmin, 'msg' => $msg, 'meta' => $meta, 'selected' => 'register')), 'content' => Template::loadTemplate('register', array('errorClass' => $errorClass, 'inputValue' => $inputValue, 'complete' => $complete, 'callback' => $callback)), 'footer' => Template::loadTemplate('footer', array('time_start' => $time_start)))); echo $html;
/** * 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); } }
throw new Exception('You failed to match the captcha to the correct number'); } if (Activation::getByUsernameEmailCount($username, $email) > 0) { header('Location: index.php?e=4'); exit; } 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');
public static function createNewUser($username, $password = null, $email) { $db = Database::getDatabase(); if (Auth::userExists($username)) { return false; } if (is_null($password)) { $password = Auth::generateStrongPassword(); } srand(time()); $u = new User(); $u->username = $username; $u->nid = self::newNid(); $u->password = self::hashedPassword($password); $u->email = $email; $u->insert(); // Create the activation code Activation::generate($u->id, 20); return $u; }