Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. public function actionLogin()
  2. {
  3. static $intervalDagen;
  4.  
  5. echo '<p>$intervalDagen<br /></p>';
  6. var_dump($intervalDagen);
  7.  
  8. if (!Yii::$app->user->isGuest && $intervalDagen <= 60) {
  9. Yii::$app->session->setFlash('failure', 'Kan niet nogmaals inloggen.');
  10. return $this->goHome();
  11. }
  12.  
  13. $model = new GebruikerLoginForm();
  14. if ($model->load(Yii::$app->request->post()) && $model->login())
  15. {
  16. $epoch = Yii::$app->user->identity->updated_at;
  17. $dt = new DateTime("@$epoch"); // convert UNIX timestamp to PHP DateTime
  18. $laatstBijgewerkt = strtotime($dt->format('d-m-Y H:i:s'));
  19. $vandaag = strtotime(date('d-m-Y H:i:s'));
  20. $intervalSeconden = $vandaag - $laatstBijgewerkt;
  21. $intervalDagen = intval($intervalSeconden / 86400);
  22.  
  23. if ($intervalDagen > 60)
  24. {
  25. $modeluser = Gebruiker::find()->where([
  26. 'username'=>Yii::$app->user->identity->username
  27. ])->one();
  28.  
  29. $changePasswordc = Yii::$app->createController('site');
  30.  
  31. $passwordChanged = $changePasswordc[0]->actionChangepassword($modeluser);
  32. echo $passwordChanged;
  33.  
  34. if ($passwordChanged)
  35. {
  36.  
  37. }
  38. else{
  39.  
  40. }
  41.  
  42. }
  43.  
  44. //return $this->goBack();
  45. return $this->goHome();
  46. }
  47. else
  48. {
  49. return $this->render('login', [
  50. 'model' => $model,
  51. ]);
  52. }
  53. }
  54.  
  55. <?php
  56. /**
  57. * Created by PhpStorm.
  58. * User: Ynze
  59. * Date: 23-1-2017
  60. * Time: 21:08
  61. */
  62.  
  63. namespace commonmodels;
  64.  
  65. use Yii;
  66. use yiibaseModel;
  67. use kartikpasswordStrengthValidator;
  68.  
  69. class ChangePasswordForm extends Model{
  70. public $oldpass;
  71. public $newpass;
  72. public $repeatnewpass;
  73.  
  74. public function rules(){
  75. return [
  76. [['oldpass','newpass','repeatnewpass'],'required'],
  77. ['oldpass','findPasswords'],
  78. ['repeatnewpass','compare','compareAttribute'=>'newpass'],
  79. [['newpass'], StrengthValidator::className(), 'preset'=>'normal', 'userAttribute'=>'username']
  80. ];
  81. }
  82.  
  83. public function findPasswords($attribute, $params){
  84. $user = Gebruiker::find()->where([
  85. 'username'=>Yii::$app->user->identity->username
  86. ])->one();
  87.  
  88. $password = $user->password;
  89. if (!$user->validatePassword($attribute))
  90. $this->addError($attribute,'Huidig wachtwoord is onjuist');
  91. }
  92.  
  93. public function attributeLabels(){
  94. return [
  95. 'oldpass'=>'Huidig wachtwoord',
  96. 'newpass'=>'Nieuw wachtwoord',
  97. 'repeatnewpass'=>'Herhaal nieuw wachtwoord',
  98. ];
  99. }
  100.  
  101. /* hier de functies om het huidige wachtwoord te controleren en de nieuwe vervolgens op te slaan */
  102. public function checkSetPassword()
  103. {
  104. return true;
  105. }
  106. }
  107.  
  108. <?php
  109. use yiihelpersHtml;
  110. use kartikwidgetsActiveForm;
  111. use kartikpasswordPasswordInput;
  112.  
  113. $this->title = 'Wijzig wachtwoord';
  114. $this->params['breadcrumbs'][] = $this->title;
  115. ?>
  116.  
  117. <div class="site-changepassword">
  118.  
  119. <div class="col-sm-offset-0 col-sm-10">
  120.  
  121. <h2><?= Html::encode($this->title) ?></h2>
  122.  
  123. <p>Vul de volgende velden in om het wachtwoord te wijzigen :</p>
  124.  
  125. <?php $form = ActiveForm::begin([
  126. 'id'=>'changepassword-form',
  127. 'type' => ActiveForm::TYPE_VERTICAL,
  128. 'fieldConfig'=>[
  129. 'template'=>"{label}n<div class="col-lg-3">
  130. {input}</div>n<div class="col-lg-5">
  131. {error}</div>",
  132. 'labelOptions'=>['class'=>'col-lg-2 control-label'],
  133. ],
  134.  
  135. ]); ?>
  136.  
  137. <div class="form-group">
  138.  
  139. <div class="col-sm-offset-0 col-sm-12">
  140.  
  141. <div class="row">
  142. <?= $form->field($model,'oldpass',['inputOptions'=>[
  143. 'placeholder'=>'Huidig wachtwoord'
  144. ]])->passwordInput() ?>
  145. </div>
  146. <!--
  147. < ?= $form->field($model,'newpass',['inputOptions'=>[
  148. 'placeholder'=>'New Password'
  149. ]])->passwordInput() ?>
  150. -->
  151.  
  152. <p />
  153.  
  154. <div class="row">
  155. <?= $form->field($model, 'newpass', ['inputOptions'=>[
  156. 'placeholder'=>'Nieuw wachtwoord'
  157. ]])->widget(PasswordInput::classname(), [
  158. 'pluginOptions' =>
  159. [
  160. 'showMeter' => true,
  161. 'toggleMask' => false
  162. ]
  163. ])
  164. ?>
  165. </div>
  166.  
  167. <p />
  168.  
  169. <div class="row">
  170. <?= $form->field($model,'repeatnewpass',['inputOptions'=>[
  171. 'placeholder'=>'Herhaal nieuwe wachtwoord'
  172. ]])->passwordInput() ?>
  173. </div>
  174. </div>
  175. </div>
  176.  
  177. <p />
  178.  
  179. <div class="form-group">
  180. <div class="col-lg-offset-0 col-lg-12">
  181. <?= Html::submitButton('Wijzig wachtwoord',[
  182. 'class'=>'btn btn-primary'
  183. ]) ?>
  184. </div>
  185. </div>
  186.  
  187. <?php ActiveForm::end(); ?>
  188. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement