Home > Web Front-end > JS Tutorial > Example code sharing of how to use Angularjs to change password

Example code sharing of how to use Angularjs to change password

黄舟
Release: 2017-05-27 13:14:56
Original
1315 people have browsed it

This article mainly introduces the example code of Angularjs. It is very good and has reference value. Friends in need can refer to it

Modify password logical thinking

First enter the old password to determine whether the old password is correct (backend judgment)

Secondly enter the new password and determine the new password format (can be Add)

Finally determine whether the new password and confirmed password input are consistent

html part

<form class="form-horizontal" role="form">
 <p class="form-group">
  <label class="col-sm-2 control-label"><i class="importance">*</i>当前密码</label>
  <p class="col-sm-6">
   <input type="text" class="form-control" ng-model="user.password">
  </p>
 </p>
 <p class="form-group">
  <label class="col-sm-2 control-label"><i class="importance">*</i>新密码</label>
  <p class="col-sm-6">
   <input type="text" class="form-control" ng-model="user.newPassword" ng-minlength="8" ng-maxlength="16" required>
  </p>
 </p>
 <p class="form-group">
  <label class="col-sm-2 control-label"><i class="importance">*</i>确认新密码</label>
  <p class="col-sm-6">
   <input type="text" class="form-control" ng-model="password_again">
  </p>
 </p>
 <p class="form-group">
  <p class="col-sm-offset-2 col-sm-10">
   <button type="submit" class="btn btn-default x_submit" ng-click="changePassword()">保存设置</button>
  </p>
 </p>
</form>
Copy after login

AngularJS part

.controller(&#39;userpswdCtrl&#39;, function($scope,Account,SweetAlert,$state,$localStorage){
 $scope.user = {}; //信息全部存在user里面
 $scope.changePassword = function(){
  if($scope.password_again === $scope.user.newPassword){  //如果两次密码输入一致
    $scope.user.accountId = $localStorage.accountId;   //获取用户id
    Account.modifyPassword($scope.user,function(data){  //修改密码
     console.log(data);
     SweetAlert.swal({
      title:&#39;&#39;,
      text: "修改成功",
      type: "success",
      showCancelButton: false,
      confirmButtonColor: "#DD6B55",
      confirmButtonText: "是",
      cancelButtonText: "否",
      closeOnConfirm: true,
      closeOnCancel: true
     })
    },function(){

    })
  }
 }
})
Copy after login

The above is the detailed content of Example code sharing of how to use Angularjs to change password. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template