def registAUser(self,message): if message['group_name']=='administrator': group_id=2 elif message['group_name']=='guest': group_id=1 self.db.rememberUser(message['name'],message['password']) message['password']=encrypt.getPasswordSHA1(message['password']) ret= user.registAUser(self.db,name=message['name'],password=message['password'],email=message['email'],group_id=group_id,gender=string.atoi(message['gender']),question=message['question'],answer=message['answer']) return ret
def resetUserPassword(database, username, answer, newpassword): flag = isUserAnswerRight(database, username, answer) if flag == True: newpassword = encrypt.getPasswordSHA1(newpassword) return database.resetUserPassword(username, newpassword) elif flag == False: return "reset user password fail" else: return flag
def userLogin(self,message): res=json.loads(self.db.encrypt.decrypt(message['data'])) res['password']=encrypt.getPasswordSHA1(res['password']) return user.userLogin(self.db,name=res['name'],password=res['password'])
def getExtractCode(self,user_id,filename,filetype): str='%i%s%s'%(user_id,filename,filetype) return encrypt.getPasswordSHA1(str)
def getRememberMeTicket(database, username): str = database.getUserRememberMeTime(username) + username return encrypt.getPasswordSHA1(str)
if getRememberMeTicket(database, username) == ticket: database.userId = database.getUserIdByName(username) userSetRememberMe(database) return getRememberMeTicket(database, username) else: return "Ticket error!" def getRememberMeTicket(database, username): str = database.getUserRememberMeTime(username) + username return encrypt.getPasswordSHA1(str) if __name__ == "__main__": sql = SqliteDatabase() print userLogin(sql, "kitty", encrypt.getPasswordSHA1("1212")) print userSetRememberMe(sql) print getUserQuestion(sql, "kitty") # print isUserAnswerRight(sql,'kitty','123144') print resetUserPassword(sql, "kitty", "kitty", "1212") print sql.getUserRememberMeTime(getLoginedUserName(sql)) print getRememberMeTicket(sql, getLoginedUserName(sql)) # saveUserData(sql,'sdfsdfdaf}','default1',"default2") # print getUserFileList(sql) # print loadUserData(sql,'filetse','data1') # print getLoginedUserName(sql) # changeUserPassword(sql,'1212') # userLogout(sql) # sql.getMaxUserId() # sql.isRecordExist('user_list') # print registAUser(sql,name='test1',password='******',email='*****@*****.**',group_id=1)