mod/login/cgibin/changePassword.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import nstart
4 import config
5 import os, sys, string, time
6 
7 from pyclearsilver.CSPage import Context
8 from MBPage import MBPage
9 
10 import neo_cgi
11 
12 from pyclearsilver.log import *
13 
14 from auth import db_auth
15 from auth import cookieauth
16 
17 class IndexPage(MBPage):
18  def setup(self):
19  hdf = self.ncgi.hdf
20  self.requestURI = hdf.getValue("Query.request", "")
21  if self.requestURI:
22  hdf.setValue("CGI.cur.request", self.requestURI)
23 
24  def display(self):
25  hdf = self.ncgi.hdf
26 
27  self.requestURI = hdf.getValue("Query.request", "")
28  if not self.requestURI:
29  self.requestURI = hdf.getValue("HTTP.Referer", "")
30 
31  if self.requestURI:
32  hdf.setValue("CGI.cur.request", self.requestURI)
33 
34 
35  def error(self, msg):
36  self.redirectUri("changePassword.py?err=%s&request=%s" % (neo_cgi.urlEscape(msg), neo_cgi.urlEscape(self.requestURI)))
37 
39  hdf = self.ncgi.hdf
40 
41  q_pw0 = hdf.getValue("Query.pw0","")
42 
43  q_pw1 = hdf.getValue("Query.pw1","")
44  q_pw2 = hdf.getValue("Query.pw2","")
45 
46 
47  requestURI = hdf.getValue("Query.request", "%swebui" % config.gBaseURL)
48 
49  if not requestURI:
50  requestURI = config.gBaseURL + self.login + "/mail/prefs.py"
51 
52  if not self.login:
53  self.redirectUri(self.requestURI)
54 
55  if not q_pw0:
56  self.error("Old password is not complete.")
57 
58  if not q_pw1 or (q_pw1 != q_pw2):
59  self.error("New passwords do not match.")
60 
61  authdb = db_auth.initSchema()
62  userRec = authdb.users.lookup(self.login)
63 
64  if not userRec.checkPassword(q_pw0):
65  self.error("Old password is invalid.")
66 
67  userRec.setPassword(q_pw1)
68 
69  cookieauth.issueLoginCookie(self.ncgi, authdb, self.login, userRec.pw_hash)
70 
71 # self.issueLoginCookie(self.login, self.MB.getOption("pw_hash"))
72 
73  warn("redirecting to", repr(self.requestURI))
74  self.redirectUri(self.requestURI)
75 
76 
77 def run(context):
78  return IndexPage(context, pagename="changePassword", checkActive=False)
79 
80 def main(context):
81  run(context).start()
82 
83 if __name__ == "__main__":
84  main(Context())


webui
Author(s): Scott Hassan
autogenerated on Mon Jun 10 2019 15:51:24