def get_current_user(self): uInfo = self.session[SESSION_USER] if uInfo: user = AdminModel.mgr().Q().filter(userName=uInfo['userName'])[0] print user if not user: self._logout() print 'get_current_user:%s' % uInfo return uInfo
def get_current_user(self): uInfo = self.session[SESSION_USER]; if uInfo: user = AdminModel.mgr().Q().filter(userName=uInfo['userName'])[0] print user if not user: self._logout() print 'get_current_user:%s'%uInfo return uInfo;
def check(self): userName = self.get_argument('userName', '').encode('utf-8') passWord = self.get_argument('passWord', '') sql = "select * from monitor_admin where userName='******' and passWord='******' and `group` in ('root','admin')" % ( userName, passWord) admins = AdminModel.mgr().raw(sql) if len(admins) > 0: self._login(admins[0]['userName']) self.send_json({}, 0, '登陆成功') else: self.send_json({}, 1, '用户名或密码错误,登陆失败')
def admindelete(self): ids = str(self.get_argument('ids')).split(",") for id in ids: admins = AdminModel.mgr().Q().filter(id=id) if admins: for admin in admins: if admin['userName'] != 'admin': admin.delete() self.write(json.dumps({'statusCode': "200", 'callbackType': "forward", 'navTabId': "admin", 'forwardUrl': "/admin/adminlist"}))
def adminlist(self): # 列表的当前页,默认在第一页 currentPage = int(self.get_argument('pageNum', 1)) # 列表中每页显示多少条,默认每页显示20条 numPerPage = int(self.get_argument('numPerPage', 20)) print 'numPerPage : %s' % numPerPage; # 计算User的总数 all = AdminModel.mgr().Q() totalCount = len(all) admins = all[(currentPage - 1) * numPerPage: currentPage * numPerPage] self.render('admin/list.html', admins=admins, currentPage=currentPage, numPerPage=numPerPage, totalCount=totalCount);
def adminlist(self): # 列表的当前页,默认在第一页 currentPage = int(self.get_argument('pageNum', 1)) # 列表中每页显示多少条,默认每页显示20条 numPerPage = int(self.get_argument('numPerPage', 20)) print 'numPerPage : %s' % numPerPage # 计算User的总数 all = AdminModel.mgr().Q() totalCount = len(all) admins = all[(currentPage - 1) * numPerPage:currentPage * numPerPage] self.render('admin/list.html', admins=admins, currentPage=currentPage, numPerPage=numPerPage, totalCount=totalCount)
def admindelete(self): ids = str(self.get_argument('ids')).split(",") for id in ids: admins = AdminModel.mgr().Q().filter(id=id) if admins: for admin in admins: if admin['userName'] != 'admin': admin.delete() self.write( json.dumps({ 'statusCode': "200", 'callbackType': "forward", 'navTabId': "admin", 'forwardUrl': "/admin/adminlist" }))
def adminpwd(self): id = self.get_argument('id', '') oldPassWord = self.get_argument('oldPassWord', '') newPassWord = self.get_argument('newPassWord', '') admins = AdminModel.mgr().Q().filter(id=id) admin = admins[0]; if admin.passWord == self.md5(oldPassWord): admin.passWord = self.md5(newPassWord) admin.save() self.write(json.dumps({'statusCode': "200", 'message': '修改成功', 'callbackType': "closeCurrent",})) else: self.write(json.dumps({'statusCode': "300", 'message': '旧密码错误', 'callbackType': "closeCurrent"}))
def adminpwd(self): id = self.get_argument('id', '') oldPassWord = self.get_argument('oldPassWord', '') newPassWord = self.get_argument('newPassWord', '') admins = AdminModel.mgr().Q().filter(id=id) admin = admins[0] if admin.passWord == self.md5(oldPassWord): admin.passWord = self.md5(newPassWord) admin.save() self.write( json.dumps({ 'statusCode': "200", 'message': '修改成功', 'callbackType': "closeCurrent", })) else: self.write( json.dumps({ 'statusCode': "300", 'message': '旧密码错误', 'callbackType': "closeCurrent" }))
def adminedit(self): id = self.get_argument('id', '0') admin = AdminModel.mgr().Q().filter(id=id)[0]; self.render('admin/edit.html', admin=admin);
def modifypwd(self): id = self.get_argument('id', '0') admin = AdminModel.mgr().Q().filter(id=id)[0]; self.render('admin/modifypwd.html', admin=admin);
def index(self): user = self.get_current_user() userName = user['userName'] admin = AdminModel.mgr().Q().filter(userName=userName)[0] self.render('index.html', admin=admin)
def adminedit(self): id = self.get_argument('id', '0') admin = AdminModel.mgr().Q().filter(id=id)[0] self.render('admin/edit.html', admin=admin)
def modifypwd(self): id = self.get_argument('id', '0') admin = AdminModel.mgr().Q().filter(id=id)[0] self.render('admin/modifypwd.html', admin=admin)