Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionLogin()
- {
- static $intervalDagen;
- echo '<p>$intervalDagen<br /></p>';
- var_dump($intervalDagen);
- if (!Yii::$app->user->isGuest && $intervalDagen <= 60) {
- Yii::$app->session->setFlash('failure', 'Kan niet nogmaals inloggen.');
- return $this->goHome();
- }
- $model = new GebruikerLoginForm();
- if ($model->load(Yii::$app->request->post()) && $model->login())
- {
- $epoch = Yii::$app->user->identity->updated_at;
- $dt = new DateTime("@$epoch"); // convert UNIX timestamp to PHP DateTime
- $laatstBijgewerkt = strtotime($dt->format('d-m-Y H:i:s'));
- $vandaag = strtotime(date('d-m-Y H:i:s'));
- $intervalSeconden = $vandaag - $laatstBijgewerkt;
- $intervalDagen = intval($intervalSeconden / 86400);
- if ($intervalDagen > 60)
- {
- $modeluser = Gebruiker::find()->where([
- 'username'=>Yii::$app->user->identity->username
- ])->one();
- $changePasswordc = Yii::$app->createController('site');
- $passwordChanged = $changePasswordc[0]->actionChangepassword($modeluser);
- echo $passwordChanged;
- if ($passwordChanged)
- {
- }
- else{
- }
- }
- //return $this->goBack();
- return $this->goHome();
- }
- else
- {
- return $this->render('login', [
- 'model' => $model,
- ]);
- }
- }
- <?php
- /**
- * Created by PhpStorm.
- * User: Ynze
- * Date: 23-1-2017
- * Time: 21:08
- */
- namespace commonmodels;
- use Yii;
- use yiibaseModel;
- use kartikpasswordStrengthValidator;
- class ChangePasswordForm extends Model{
- public $oldpass;
- public $newpass;
- public $repeatnewpass;
- public function rules(){
- return [
- [['oldpass','newpass','repeatnewpass'],'required'],
- ['oldpass','findPasswords'],
- ['repeatnewpass','compare','compareAttribute'=>'newpass'],
- [['newpass'], StrengthValidator::className(), 'preset'=>'normal', 'userAttribute'=>'username']
- ];
- }
- public function findPasswords($attribute, $params){
- $user = Gebruiker::find()->where([
- 'username'=>Yii::$app->user->identity->username
- ])->one();
- $password = $user->password;
- if (!$user->validatePassword($attribute))
- $this->addError($attribute,'Huidig wachtwoord is onjuist');
- }
- public function attributeLabels(){
- return [
- 'oldpass'=>'Huidig wachtwoord',
- 'newpass'=>'Nieuw wachtwoord',
- 'repeatnewpass'=>'Herhaal nieuw wachtwoord',
- ];
- }
- /* hier de functies om het huidige wachtwoord te controleren en de nieuwe vervolgens op te slaan */
- public function checkSetPassword()
- {
- return true;
- }
- }
- <?php
- use yiihelpersHtml;
- use kartikwidgetsActiveForm;
- use kartikpasswordPasswordInput;
- $this->title = 'Wijzig wachtwoord';
- $this->params['breadcrumbs'][] = $this->title;
- ?>
- <div class="site-changepassword">
- <div class="col-sm-offset-0 col-sm-10">
- <h2><?= Html::encode($this->title) ?></h2>
- <p>Vul de volgende velden in om het wachtwoord te wijzigen :</p>
- <?php $form = ActiveForm::begin([
- 'id'=>'changepassword-form',
- 'type' => ActiveForm::TYPE_VERTICAL,
- 'fieldConfig'=>[
- 'template'=>"{label}n<div class="col-lg-3">
- {input}</div>n<div class="col-lg-5">
- {error}</div>",
- 'labelOptions'=>['class'=>'col-lg-2 control-label'],
- ],
- ]); ?>
- <div class="form-group">
- <div class="col-sm-offset-0 col-sm-12">
- <div class="row">
- <?= $form->field($model,'oldpass',['inputOptions'=>[
- 'placeholder'=>'Huidig wachtwoord'
- ]])->passwordInput() ?>
- </div>
- <!--
- < ?= $form->field($model,'newpass',['inputOptions'=>[
- 'placeholder'=>'New Password'
- ]])->passwordInput() ?>
- -->
- <p />
- <div class="row">
- <?= $form->field($model, 'newpass', ['inputOptions'=>[
- 'placeholder'=>'Nieuw wachtwoord'
- ]])->widget(PasswordInput::classname(), [
- 'pluginOptions' =>
- [
- 'showMeter' => true,
- 'toggleMask' => false
- ]
- ])
- ?>
- </div>
- <p />
- <div class="row">
- <?= $form->field($model,'repeatnewpass',['inputOptions'=>[
- 'placeholder'=>'Herhaal nieuwe wachtwoord'
- ]])->passwordInput() ?>
- </div>
- </div>
- </div>
- <p />
- <div class="form-group">
- <div class="col-lg-offset-0 col-lg-12">
- <?= Html::submitButton('Wijzig wachtwoord',[
- 'class'=>'btn btn-primary'
- ]) ?>
- </div>
- </div>
- <?php ActiveForm::end(); ?>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement