Commit b83435ea by Alexander Makarov

Merge pull request #2446 from Theill11/update-apps

Minor updates to apps
parents e1f4a9cc f42af951
......@@ -54,11 +54,11 @@ class SiteController extends Controller
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
$this->goHome();
return $this->goHome();
}
$model = new LoginForm();
if ($model->load($_POST) && $model->login()) {
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', [
......
<?php
namespace common\models;
use yii\base\Model;
use Yii;
use yii\base\Model;
/**
* Login form
......@@ -44,12 +44,13 @@ class LoginForm extends Model
/**
* Logs in a user using the provided username and password.
*
* @return boolean whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0);
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
} else {
return false;
}
......
......@@ -27,6 +27,12 @@ class User extends ActiveRecord implements IdentityInterface
const ROLE_USER = 10;
/**
* Creates a new user
*
* @param array $attributes the attributes given by field => value
* @return static|null the newly created model, or null on failure
*/
public static function create($attributes)
{
/** @var User $user */
......@@ -69,18 +75,18 @@ class User extends ActiveRecord implements IdentityInterface
* Finds user by username
*
* @param string $username
* @return self
* @return static|null
*/
public static function findByUsername($username)
{
return static::find(['username' => $username, 'status' => static::STATUS_ACTIVE]);
return static::find(['username' => $username, 'status' => self::STATUS_ACTIVE]);
}
/**
* Finds user by password reset token
*
* @param string $token password reset token
* @return self
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
......@@ -92,9 +98,9 @@ class User extends ActiveRecord implements IdentityInterface
return null;
}
return User::find([
return static::find([
'password_reset_token' => $token,
'status' => User::STATUS_ACTIVE,
'status' => self::STATUS_ACTIVE,
]);
}
......
......@@ -65,7 +65,7 @@ class SiteController extends Controller
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
$this->goHome();
return $this->goHome();
}
$model = new LoginForm();
......@@ -86,8 +86,8 @@ class SiteController extends Controller
public function actionContact()
{
$model = new ContactForm;
if ($model->load($_POST) && $model->contact(Yii::$app->params['adminEmail'])) {
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
return $this->refresh();
} else {
......@@ -144,7 +144,7 @@ class SiteController extends Controller
throw new BadRequestHttpException($e->getMessage());
}
if ($model->load($_POST) && $model->resetPassword()) {
if ($model->load(Yii::$app->request->post()) && $model->resetPassword()) {
Yii::$app->getSession()->setFlash('success', 'New password was saved.');
return $this->goHome();
}
......
......@@ -17,7 +17,7 @@ class ContactForm extends Model
public $verifyCode;
/**
* @return array the validation rules.
* @inheritdoc
*/
public function rules()
{
......@@ -32,7 +32,7 @@ class ContactForm extends Model
}
/**
* @return array customized attribute labels
* @inheritdoc
*/
public function attributeLabels()
{
......@@ -43,6 +43,7 @@ class ContactForm extends Model
/**
* Sends an email to the specified email address using the information collected by this model.
*
* @param string $email the target email address
* @return boolean whether the model passes validation
*/
......
......@@ -25,8 +25,9 @@ class PasswordResetRequestForm extends Model
}
/**
* Sends an email with a link, for resetting the password.
*
* @return boolean sends an email
* @return boolean whether the email was send
*/
public function sendEmail()
{
......@@ -52,4 +53,3 @@ class PasswordResetRequestForm extends Model
return false;
}
}
\ No newline at end of file
......@@ -19,7 +19,7 @@ class ResetPasswordForm extends Model
private $_user;
/**
* Creates a form model given a token
* 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
......@@ -38,7 +38,7 @@ class ResetPasswordForm extends Model
}
/**
* @return array the validation rules.
* @inheritdoc
*/
public function rules()
{
......@@ -50,6 +50,7 @@ class ResetPasswordForm extends Model
/**
* Resets password.
*
* @return boolean if password was reset.
*/
public function resetPassword()
......@@ -60,4 +61,3 @@ class ResetPasswordForm extends Model
return $user->save();
}
}
\ No newline at end of file
......@@ -36,7 +36,8 @@ class SignupForm extends Model
/**
* Signs user up.
* @return User saved model
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
......@@ -46,4 +47,3 @@ class SignupForm extends Model
return null;
}
}
\ No newline at end of file
......@@ -55,11 +55,11 @@ class SiteController extends Controller
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
$this->goHome();
return $this->goHome();
}
$model = new LoginForm();
if ($model->load($_POST) && $model->login()) {
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', [
......@@ -76,8 +76,8 @@ class SiteController extends Controller
public function actionContact()
{
$model = new ContactForm;
if ($model->load($_POST) && $model->contact(Yii::$app->params['adminEmail'])) {
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
} else {
......
......@@ -24,11 +24,20 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface
],
];
/**
* @inheritdoc
*/
public static function findIdentity($id)
{
return isset(self::$users[$id]) ? new static(self::$users[$id]) : null;
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
foreach (self::$users as $user) {
......@@ -39,21 +48,36 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface
return null;
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->id;
}
/**
* @inheritdoc
*/
public function getAuthKey()
{
return $this->authKey;
}
/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
return $this->authKey === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return bool if password provided is valid for current user
*/
public function validatePassword($password)
{
return $this->password === $password;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment