summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/admin/password.js
blob: 41d6ed623bf19aba7e3b860232f502f9d3374aed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var ChangePasswordForm = FormView.extend({

  el: "#admin_changePassword",

  events: {
  },

  action: "/api/admin/password/",
  method: "put",

  initialize: function(opt){
    this.__super__.initialize.call(this, opt)
    this.$select = this.$("select")
  },

  load: function(usernames){
    usernames = usernames || []
    usernames.forEach(username => {
      option = document.createElement("option")
      option.value = username
      option.innerHTML = sanitize(username)
      this.$select.append(option)
    })
    this.$select.show()
  },

  validate: function(){
    var errors = []
    var pw = $("[name=password]").val()
    var pw1 = $("[name=newpassword]").val()
    var pw2 = $("[name=newpassword2]").val()
    if (! pw) {
      errors.push("Please enter your password.")
    }
    if (! pw1 || ! pw2) {
      errors.push("Please enter the new password for this user.")
    }
    if (pw1 && pw2 && pw1 !== pw2) {
      errors.push("Passwords don't match.")
    }
    return errors.length ? errors : null
  },

  success: function(data){
    this.$("[name]").val('')
    this.$("select").val('Select a user...')
    // window.location.reload()
    console.log(this)
    console.log(this.parent)
    this.showErrors(['password changed'])
  },

})