public function actionRecover($key = null) { if ($key) { $user = User::objects()->get(['activation_key' => $key]); if ($user === null) { echo $this->json(['status' => false, 'error' => 'User not found']); $this->end(); } $user->password = ''; $user->save(['password']); $form = new ChangePasswordForm(); $form->setModel($user); $r = $this->getRequest(); if ($r->getIsPost() && $form->populate($_POST)->isValid() && $form->save()) { echo $this->json(['status' => true, 'message' => UserModule::t('Password changed')]); $this->end(); } else { echo $this->json(['errors' => $form->getJsonErrors()]); $this->end(); } } else { $form = new RecoverForm(); if ($form->populate($_POST)->isValid() && $form->send()) { echo $this->json(['status' => true]); } else { echo $this->json(['errors' => $form->getJsonErrors()]); } } }
public function cleanUsername($value) { if (User::objects()->filter(['username' => $value])->count() > 0) { $this->addError('username', UserModule::t('This username is already in use on the site')); } return $value; }
public function actionLogin() { $app = Mindy::app(); if (!$app->user->getIsGuest()) { $model = $app->getUser(); $key = Key::objects()->get(['user' => $model]); echo $this->json(['status' => true, 'errors' => [], 'user' => UserHelper::userToJson($model, $key ? $key->key : null), 'message' => UserModule::t('You have successfully logged in to the site')]); $this->end(); } $form = new LoginForm(); $r = $this->getRequest(); if ($r->getIsPost() && $form->setAttributes($_POST)->isValid() && $form->login()) { $model = $form->getUser(); $this->clearKeys($model); $authKey = md5(Password::generateSalt()); $key = new Key(['user' => $model, 'key' => $authKey]); if ($key->save() === false) { echo $this->json(['status' => false, 'error' => 'Failed to save token']); $this->end(); } $data = ['errors' => [], 'status' => true, 'user' => UserHelper::userToJson($model, $authKey), 'message' => UserModule::t('You have successfully logged in to the site')]; } else { $data = ['errors' => $form->getErrors()]; } echo $this->json($data); $this->end(); }
public function getFields() { $fields = ['password_current' => ['class' => PasswordField::className(), 'label' => UserModule::t('Current password'), 'hint' => UserModule::t('Enter your current password to confirm')], 'password_create' => ['class' => PasswordField::className(), 'validators' => [new MinLengthValidator(6)], 'label' => UserModule::t('Password')], 'password_repeat' => ['class' => PasswordField::className(), 'validators' => [new MinLengthValidator(6)], 'label' => UserModule::t('Password repeat'), 'hint' => UserModule::t('Please repeat your password')]]; if (empty($this->getModel()->password)) { unset($fields['password_current']); } return $fields; }
public function getFields() { $years = [null => '']; foreach (range(1990, (int) date('Y')) as $year) { $years[] = $year; } return array_merge(parent::getFields(), ['post' => ['class' => CharField::class, 'label' => UserModule::t('Post')], 'direction' => ['class' => CharField::class, 'label' => UserModule::t('Direction')], 'job_start_at' => ['class' => DropDownField::class, 'choices' => $years, 'label' => UserModule::t('Job start at')], 'job_end_at' => ['class' => DropDownField::class, 'choices' => $years, 'label' => UserModule::t('Job end at')]]); }
public function actionIndex() { $this->addBreadcrumb(UserModule::t("Registration")); $form = new RegistrationForm(); if ($this->getRequest()->isPost && $form->populate($_POST)->isValid() && $form->save()) { $this->getRequest()->redirect('user:registration_success'); } echo $this->render('user/registration.html', ['form' => $form]); }
public function cleanUsername_or_email() { $field = strpos($this->username_or_email->getValue(), "@") ? 'email' : 'username'; $this->_model = User::objects()->get([$field => $this->username_or_email->getValue()]); if ($this->_model === null) { $this->username_or_email->addError(UserModule::t('User not found')); } return $this->_model; }
public function getFields() { return ['email' => ['class' => EmailField::class, 'label' => UserModule::t('Email'), 'validators' => [function ($value) { $count = User::objects()->filter(['email' => $value, 'is_active' => false])->count(); if ($count == 0) { return UserModule::t("User with this email address not found"); } return true; }]]]; }
public function getFields() { return ['code' => ['class' => CharField::class, 'label' => UserModule::t('Code from SMS message'), 'validators' => [new MinLengthValidator(4), new RequiredValidator(), function ($value) { $count = User::objects()->filter(['sms_key' => $value, 'is_active' => false])->count(); if ($count == 0) { return UserModule::t("Incorrect activation key"); } return true; }]]]; }
public function getFields() { return ['phone' => ['class' => CharField::class, 'label' => UserModule::t('Phone'), 'validators' => [function ($value) { $count = User::objects()->filter(['phone' => $value, 'is_active' => false])->count(); if ($count == 0) { return UserModule::t("User with this phone number not found"); } return true; }]]]; }
public function actionSmsConfirm() { $this->setBreadcrumbs([['name' => UserModule::t('Login'), 'url' => Mindy::app()->urlManager->reverse('user:login')], ['name' => 'Повторная отправка SMS для активации учетной записи', 'url' => Mindy::app()->urlManager->reverse('user:activation_sms')], ['name' => 'Подтверждение учетной записи по смс']]); $form = new SmsConfirmForm(); $request = $this->getRequest(); if ($request->getIsPost() && $form->populate($request->post->all())->isValid() && $form->activate()) { $request->redirect(Mindy::app()->urlManager->reverse('user:activation_sms_success')); } echo $this->render('user/activation/sms_confirm.html', ['form' => $form]); }
public function getFields() { $years = [null => '']; foreach (range(1990, (int) date('Y')) as $year) { $years[] = $year; } $classes = []; foreach (Classroom::objects()->valuesList(['id', 'name']) as $cls) { $classes[$cls['id']] = $cls['name']; } return array_merge(parent::getFields(), ['classroom' => ['class' => DropDownField::class, 'label' => ClassroomModule::t('Classroom'), 'choices' => $classes], 'education_start_at' => ['class' => DropDownField::class, 'choices' => $years, 'label' => UserModule::t('Education start date')], 'education_end_at' => ['class' => DropDownField::class, 'choices' => $years, 'label' => UserModule::t('Education end date')]]); }
public function actionChangePassword() { $user = Mindy::app()->getUser(); $form = new ChangePasswordForm(); $form->setModel($user); $r = $this->getRequest(); if ($r->getIsPost() && $form->populate($_POST)->isValid() && $form->save()) { echo $this->json(['status' => true, 'message' => UserModule::t('Password changed')]); $this->end(); } else { echo $this->json(['errors' => $form->getJsonErrors()]); $this->end(); } }
public function actionChangepassword() { $model = Mindy::app()->user; if ($this->getModule()->userList) { $this->addBreadcrumb(UserModule::t("Users"), Mindy::app()->urlManager->reverse('user:list')); } $this->addBreadcrumb($model, $model->getAbsoluteUrl()); $this->addBreadcrumb(UserModule::t("Change password")); $form = new ChangePasswordForm(['model' => $model]); if ($this->getRequest()->isPost && $form->populate($_POST)->isValid() && $form->save()) { $this->getRequest()->flash->success(UserModule::t('Password changed')); $this->getRequest()->redirect('user:login'); } echo $this->render('user/change_password.html', ['form' => $form, 'model' => $model]); }
public function getFields() { $fields = parent::getFields(); $newFields = array_merge($fields, ['last_name' => ['class' => CharField::class, 'label' => UserModule::t('Last name')], 'first_name' => ['class' => CharField::class, 'label' => UserModule::t('First name')], 'middle_name' => ['class' => CharField::class, 'label' => UserModule::t('Middle name')], 'phone' => ['class' => CharField::class, 'label' => UserModule::t('Phone'), 'hint' => 'На данный номер телефона придет смс с подтверждением регистрации', 'validators' => [function ($value) { if (User::objects()->filter(['phone' => $value])->count() > 0) { return UserModule::t("Phone must be a unique"); } return true; }]], 'i_accept_license' => ['class' => CheckboxField::class, 'required' => true, 'label' => UserModule::t('I accept the license')]]); if (isset($fields['captcha'])) { $captcha = $fields['captcha']; unset($fields['captcha']); return array_merge($newFields, [$captcha]); } return $newFields; }
public function actionActivate($key) { $model = User::objects()->filter(['activation_key' => $key])->get(); if ($model === null) { $this->error(404); } if ($model->activation_key === $key) { $form = new ChangePasswordForm(['model' => $model]); if ($this->getRequest()->isPost && $form->populate($_POST)->isValid() && $form->save()) { $this->getRequest()->flash->success(UserModule::t('Password changed')); $this->getRequest()->redirect('user:login'); } else { echo $this->render('user/recover_change_password.html', ['form' => $form, 'model' => $model, 'key' => $key]); } } else { echo $this->render('user/change_password_incorrect.html'); } }
public function actionLogin() { $request = $this->getRequest(); $app = Mindy::app(); if ($app->getUser()->getIsGuest() === false) { $request->redirect('user:profile'); } $this->addBreadcrumb(UserModule::t("Login")); $form = new LoginForm(); if ($request->getIsPost() && $form->populate($_POST)->isValid() && $form->login()) { $this->redirectNext(); if ($request->getIsAjax()) { echo $this->json(['status' => 'success', 'title' => UserModule::t('You have successfully logged in to the site')]); Mindy::app()->end(); } else { $request->redirect('user:profile'); } } echo $this->render('user/login.html', ['form' => $form]); }
/** * Authenticates the password. * This is the 'authenticate' validator as declared in rules(). */ public function authenticate() { if ($this->_identity === null) { $this->_identity = new UserIdentity($this->username->getValue(), $this->password->getValue()); } if (!$this->_identity->authenticate()) { switch ($this->_identity->errorCode) { case UserIdentity::ERROR_EMAIL_INVALID: $this->addError("username", UserModule::t("Email is incorrect.")); break; case UserIdentity::ERROR_USERNAME_INVALID: $this->addError("username", UserModule::t("Username is incorrect.")); break; case UserIdentity::ERROR_PASSWORD_INVALID: $this->addError("password", UserModule::t("Password is incorrect.")); break; case UserIdentity::ERROR_INACTIVE: $this->setIsActive(false); $this->addError("username", UserModule::t("Account not active. Please activate your account.")); break; } } }
public function getFieldsets() { return [UserModule::t('Main information') => ['code', 'name', 'bizrule'], UserModule::t('Settings') => ['is_visible', 'is_locked', 'is_default', 'is_global', 'is_auto']]; }
public function getFieldsets() { return [UserModule::t('Main information') => ['name', 'description'], UserModule::t('Settings') => ['is_visible', 'is_locked'], UserModule::t('Permissions') => ['permissions']]; }
/** * Return array of mail templates and his variables * @return array */ public function getMailTemplates() { return ['registration' => ['username' => UserModule::t('Username'), 'activation_url' => UserModule::t('Url with activation key'), 'sitename' => CoreModule::t('Site name')], 'recovery' => ['recover_url' => UserModule::t('Url with link to recover password')], 'changepassword' => ['changepassword_url' => UserModule::t('Url with link to change password')], 'activation' => []]; }
public function getFieldsets() { return [UserModule::t('Main information') => ['username', 'email', 'is_staff', 'is_superuser', 'is_active'], UserModule::t('Extra information') => ['groups', 'permissions']]; }
public static function getFields() { return ['owner_id' => ['class' => IntField::className(), 'verboseName' => UserModule::t("Owner")], 'type' => ['class' => IntField::className(), 'choices' => [Permissions::TYPE_USER, Permissions::TYPE_GROUP], 'verboseName' => UserModule::t("Type")], 'permission' => ['class' => ForeignField::className(), 'modelClass' => PermissionObject::className(), 'verboseName' => UserModule::t("Permission")]]; }
public function actionChangepassword($id) { $auth = Mindy::app()->auth; if ($auth->isGuest) { $this->r->redirect(Mindy::app()->homeUrl); } $model = User::objects()->filter(['pk' => $id])->get(); if ($model === null) { $this->error(404); } $admin = new UserAdmin(); $this->addBreadcrumb(Text::mbUcfirst($admin->getVerboseName()), Mindy::app()->urlManager->reverse('admin:list', ['module' => User::getModuleName(), 'adminClass' => $admin->classNameShort()])); $this->addBreadcrumb((string) $model, Mindy::app()->urlManager->reverse('admin:update', ['module' => User::getModuleName(), 'adminClass' => $admin->classNameShort(), 'id' => $id])); $this->addBreadcrumb(UserModule::t('Change password')); $form = new ChangePasswordForm(['model' => $model]); if ($this->r->isPost && $form->populate($_POST)->isValid() && $form->save()) { $this->r->flash->success(UserModule::t('Password changed')); $this->r->http->refresh(); } echo $this->render('admin/changepassword.html', ['model' => $model, 'form' => $form]); }
public static function getFields() { return ['user' => ['class' => ForeignField::className(), 'modelClass' => User::className(), 'verboseName' => UserModule::t('User')], 'key' => ['class' => CharField::className(), 'length' => 40, 'verboseName' => UserModule::t("Key"), 'unique' => true]]; }
public function login(Model $model, $duration = null) { $time = $model->getDb()->getQueryBuilder()->convertToDateTime(time()); $model->last_login = $time; $model->save(['last_login']); if ($duration === null) { $duration = Mindy::app()->getModule('User')->loginDuration; } $this->saveToCookie($model, $duration); if ($this->absoluteAuthTimeout) { $this->getStorage()->add(self::AUTH_ABSOLUTE_TIMEOUT_VAR, time() + $this->absoluteAuthTimeout); } $model->setIsGuest(false); $this->setModel($model); $sessionId = Mindy::app()->session->getId(); $session = Session::objects()->get(['id' => $sessionId]); if ($session) { $session->user = $model; $session->save(); } $this->getEventManager()->send($this, 'onAuth', $model); if (class_exists('\\Modules\\UserActions\\Models\\UserLog')) { \Modules\UserActions\Models\UserLog::objects()->create(['message' => UserModule::t('User <a href="{url}">{name}</a> logged in', ['{url}' => $model->getAbsoluteUrl(), '{name}' => (string) $model]), 'module' => $model->getModuleName(), 'ip' => $model->getIp(), 'user' => $model]); } return !$this->getIsGuest(); }
public static function getFields() { return ['user_group' => ['class' => ForeignField::className(), 'modelClass' => Group::className(), 'verboseName' => UserModule::t("Group")], 'permission' => ['class' => ForeignField::className(), 'modelClass' => Permission::className(), 'verboseName' => UserModule::t("Permission")]]; }