コード例 #1
0
ファイル: Users.php プロジェクト: anavallasuiza/laravel-admin
 private function getRow($id)
 {
     if (empty($id)) {
         return new Models\User();
     }
     return Models\User::where('id', $id)->firstOrFail();
 }
コード例 #2
0
ファイル: LoginForm.php プロジェクト: gitter-badger/luya
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = \admin\models\User::findByEmail($this->email);
     }
     return $this->_user;
 }
コード例 #3
0
ファイル: Users.php プロジェクト: anavallasuiza/laravel-admin
 public function edit($form, $row)
 {
     if (!($data = $this->check(__FUNCTION__, $form))) {
         return $data;
     }
     if ($data['password'] !== $data['password_repeat']) {
         throw new Exception(__('Passwords must be equals.'));
     }
     $exists = Models\User::where('user', '=', $data['user'])->where('id', '!=', $data['id'])->first();
     if ($exists) {
         throw new Exception(__('Already exists another user with user "%s"', $data['user']));
     }
     if ($data['password']) {
         $data['password'] = Hash::make($data['password']);
     } elseif (empty($data['id'])) {
         throw new Exception(__('Password is required for new users'));
     } else {
         unset($data['password']);
     }
     unset($data['password_repeat']);
     try {
         $row = Models\User::replace($data, $row);
     } catch (Exception $e) {
         throw new Exception(__('Error storing data: %s', $e->getMessage()));
     }
     Session::flash('flash-message', ['message' => __('Data was saved successfully'), 'status' => 'success']);
     return Redirect::route('admin.management.users.edit', $row->id);
 }
コード例 #4
0
ファイル: LoginForm.php プロジェクト: egorlost/mysite
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
コード例 #5
0
ファイル: Group.php プロジェクト: kimonaris/luya
 public function ngRestConfig($config)
 {
     $config->aw->register(new \admin\aws\GroupAuth(), 'Berechtigungen');
     $config->delete = true;
     $config->list->field('name', 'Name')->text();
     $config->list->field('text', 'Beschreibung')->textarea();
     $config->create->copyFrom('list', ['id']);
     $config->create->extraField('users', 'Benutzer')->checkboxRelation(\admin\models\User::className(), 'admin_user_group', 'group_id', 'user_id', ['firstname', 'lastname', 'email'], '%s %s (%s)');
     $config->update->copyFrom('create');
     return $config;
 }
コード例 #6
0
ファイル: Group.php プロジェクト: gitter-badger/luya
 public function ngRestConfig($config)
 {
     $config->aw->register(new \admin\aws\GroupAuth(), Module::t('model_group_btn_aws_groupauth'));
     $config->delete = true;
     $config->list->field('name', Module::t('model_group_name'))->text();
     $config->list->field('text', Module::t('model_group_description'))->textarea();
     $config->create->copyFrom('list', ['id']);
     $config->create->extraField('users', Module::t('model_group_user_buttons'))->checkboxRelation(\admin\models\User::className(), 'admin_user_group', 'group_id', 'user_id', ['firstname', 'lastname', 'email'], '%s %s (%s)');
     $config->update->copyFrom('create');
     return $config;
 }
コード例 #7
0
ファイル: ConfirmEmailForm.php プロジェクト: egorlost/mysite
 /**
  * Creates a form model given a token.
  *
  * @param  string $token
  * @param  array $config
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         throw new InvalidParamException('Отсутствует код подтверждения.');
     }
     $this->_user = User::findByEmailConfirmToken($token);
     if (!$this->_user) {
         throw new InvalidParamException('Неверный токен.');
     }
     parent::__construct($config);
 }
コード例 #8
0
ファイル: ResetPasswordForm.php プロジェクト: egorlost/mysite
 /**
  * Creates a form model given a token.
  *
  * @param  string                          $token
  * @param  array                           $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         throw new InvalidParamException('Password reset token cannot be blank.');
     }
     $this->_user = User::findByPasswordResetToken($token);
     if (!$this->_user) {
         throw new InvalidParamException('Wrong password reset token.');
     }
     parent::__construct($config);
 }
コード例 #9
0
ファイル: UserOnline.php プロジェクト: efueger/luya
 public static function getList()
 {
     $time = time();
     $return = [];
     foreach (self::find()->asArray()->all() as $item) {
         $user = User::findOne($item['user_id']);
         if ($user) {
             $inactiveSince = $time - $item['last_timestamp'];
             $return[] = ['firstname' => $user->firstname, 'lastname' => $user->lastname, 'email' => $user->email, 'last_timestamp' => $item['last_timestamp'], 'is_active' => $inactiveSince >= 120 ? false : true, 'inactive_since' => round($inactiveSince / 60) . ' min'];
         }
     }
     return $return;
 }
コード例 #10
0
 /**
  * @todo don't write directly in db table (admin_user_group)
  * @todo reuse encode password function from user model
  * @todo find better solution for while(true)/break loop
  * @todo find better solution for title array/selection
  * @todo error handling (validate, can't save models)
  *
  * @param $title
  * @param $firstname
  * @param $lastname
  * @param $email
  * @param $password
  */
 public function actionUser()
 {
     while (true) {
         $email = $this->prompt('Benutzer E-Mail:');
         if (!empty(User::findByEmail($email))) {
             $this->outputError('Email existiert bereits!');
         } else {
             break;
         }
     }
     $titleArray = ['Herr' => 1, 'Frau' => 2];
     $title = $this->select('Anrede:', ['Herr' => '1', 'Frau' => '2']);
     $firstname = $this->prompt('Vorname:');
     $lastname = $this->prompt('Nachname:');
     $password = $this->prompt('Benutzer Passwort:');
     if (!$this->confirm("Einen neuen Benutzer '{$title} {$firstname} {$lastname}, Email {$email}' mit dem Passwort '{$password}' anlegen?")) {
         return $this->outputError('Abort user creation process.');
     }
     $user = new User();
     $user->email = $email;
     $user->password_salt = Yii::$app->getSecurity()->generateRandomString();
     $user->password = Yii::$app->getSecurity()->generatePasswordHash($password . $user->password_salt);
     $user->firstname = $firstname;
     $user->lastname = $lastname;
     $user->title = $titleArray[$title];
     $user->save();
     $userId = $user->id;
     $groupEntries = Group::find()->all();
     $groupSelect = [];
     $this->output('');
     foreach ($groupEntries as $entry) {
         $groupSelect[$entry->id] = $entry->name . ' (' . $entry->text . ')';
         $this->output($entry->id . ' - ' . $groupSelect[$entry->id]);
     }
     $groupId = $this->select('Benutzergruppe:', $groupSelect);
     $this->insert('admin_user_group', ['user_id' => $userId, 'group_id' => $groupId]);
     return $this->outputSuccess("Der Benutzer {$firstname} {$lastname} wurde erfolgreich angelegt.");
 }
コード例 #11
0
 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     /* @var $user User */
     $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]);
     if ($user) {
         if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
             $user->generatePasswordResetToken();
         }
         if ($user->save()) {
             return \Yii::$app->mailer->compose(['text' => 'passwordResetToken-text'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send();
         }
     }
     return false;
 }
コード例 #12
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $data = $this->option();
     $exists = Models\User::where('user', '=', $data['user'])->first();
     if ($exists) {
         $this->error(__('User %s alread exists', $data['user']));
         return false;
     }
     try {
         Models\User::create(['name' => $data['name'], 'user' => $data['user'], 'password' => Hash::make($data['password']), 'admin' => $data['admin'] && $data['admin'] !== 'false', 'enabled' => 1]);
     } catch (Exception $e) {
         $this->error($e->getMessage());
         return false;
     }
     $this->info('User created successfully');
 }
コード例 #13
0
ファイル: User.php プロジェクト: efueger/luya
 public function ngRestConfig($config)
 {
     $config->aw->register(new \admin\aws\ChangePassword(), 'Passwort ändern');
     //$config->activeWindow->register(new \admin\aws\Delete(), 'Löschen');
     $config->create->field('title', 'Anrede')->selectArray(\admin\models\User::getTitles(), 0);
     $config->create->field('firstname', 'Vorname')->text();
     $config->create->field('lastname', 'Nachname')->text();
     $config->create->field('email', 'E-Mail-Adresse')->text();
     $config->create->field('password', 'Passwort')->password();
     $config->list->field('id', 'ID')->text();
     $config->list->field('firstname', 'Vorname')->text();
     $config->list->field('lastname', 'Nachname')->text();
     $config->list->field('email', 'E-Mail')->text();
     $config->update->copyFrom('create', ['password']);
     $config->delete = true;
     return $config;
 }
コード例 #14
0
ファイル: SignupForm.php プロジェクト: egorlost/mysite
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->phone = $this->phone;
         $user->type = $this->type;
         $user->status = User::STATUS_WAIT;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->generateEmailConfirmToken();
         if ($user->save()) {
             Yii::$app->mailer->compose(['text' => 'confirmEmail'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name])->setTo($this->email)->setSubject('Email confirmation for ' . Yii::$app->name)->send();
         }
         return $user;
     }
     return null;
 }
コード例 #15
0
ファイル: Item.php プロジェクト: krystian-thiede/luya
 /**
  * Returns an active record object for the admin user who last time updated this page.
  *
  * @return \admin\models\User|boolean Returns an ActiceRecord for the admin user who last time updated this page, if not
  * found the return value is false.
  */
 public function getUserUpdated()
 {
     return User::findOne($this->itemArray['update_user_id']);
 }
コード例 #16
0
ファイル: Rental.php プロジェクト: pistej/yii2-book-library
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }