Go to the documentation of this file.00001
00002
00003 import nstart
00004 import config
00005 import os, sys, string, time
00006
00007 from pyclearsilver.CSPage import Context
00008 from MBPage import MBPage
00009
00010 import neo_cgi
00011
00012 from pyclearsilver.log import *
00013
00014 from auth import db_auth
00015 from auth import cookieauth
00016
00017 class IndexPage(MBPage):
00018 def setup(self):
00019 hdf = self.ncgi.hdf
00020 self.requestURI = hdf.getValue("Query.request", "")
00021 if self.requestURI:
00022 hdf.setValue("CGI.cur.request", self.requestURI)
00023
00024 def display(self):
00025 hdf = self.ncgi.hdf
00026
00027 self.requestURI = hdf.getValue("Query.request", "")
00028 if not self.requestURI:
00029 self.requestURI = hdf.getValue("HTTP.Referer", "")
00030
00031 if self.requestURI:
00032 hdf.setValue("CGI.cur.request", self.requestURI)
00033
00034
00035 def error(self, msg):
00036 self.redirectUri("changePassword.py?err=%s&request=%s" % (neo_cgi.urlEscape(msg), neo_cgi.urlEscape(self.requestURI)))
00037
00038 def Action_changePassword(self):
00039 hdf = self.ncgi.hdf
00040
00041 q_pw0 = hdf.getValue("Query.pw0","")
00042
00043 q_pw1 = hdf.getValue("Query.pw1","")
00044 q_pw2 = hdf.getValue("Query.pw2","")
00045
00046
00047 requestURI = hdf.getValue("Query.request", "%swebui" % config.gBaseURL)
00048
00049 if not requestURI:
00050 requestURI = config.gBaseURL + self.login + "/mail/prefs.py"
00051
00052 if not self.login:
00053 self.redirectUri(self.requestURI)
00054
00055 if not q_pw0:
00056 self.error("Old password is not complete.")
00057
00058 if not q_pw1 or (q_pw1 != q_pw2):
00059 self.error("New passwords do not match.")
00060
00061 authdb = db_auth.initSchema()
00062 userRec = authdb.users.lookup(self.login)
00063
00064 if not userRec.checkPassword(q_pw0):
00065 self.error("Old password is invalid.")
00066
00067 userRec.setPassword(q_pw1)
00068
00069 cookieauth.issueLoginCookie(self.ncgi, authdb, self.login, userRec.pw_hash)
00070
00071
00072
00073 warn("redirecting to", repr(self.requestURI))
00074 self.redirectUri(self.requestURI)
00075
00076
00077 def run(context):
00078 return IndexPage(context, pagename="changePassword", checkActive=False)
00079
00080 def main(context):
00081 run(context).start()
00082
00083 if __name__ == "__main__":
00084 main(Context())