示例#1
0
def resolve(args):
    if len(args) == 1 and args[0] == "help":
        return (0, help_info())
    if len(args) != 2:
        return (0, PF.normal_info("input arguments error, input 'login help' to get help"))
    try:
        sql_connect = pymysql.connect(
            host=SQL.Sql_Host,
            user=SQL.Sql_User,
            passwd=SQL.Sql_Password,
            database=SQL.Sql_Database,
            charset=SQL.Sql_Charset,
            connect_timeout=SQL.Sql_TimeOut,
        )
    except Exception:
        return (0, PF.error_info("sql connect error"))
    event_handler = sql_connect.cursor()
    query_string = SQL.Sql_Select_User % (args[0])
    # print(query_string)
    if not event_handler.execute(query_string):
        return (0, PF.normal_info("user " + args[0] + " dose not exist"))
    try:
        user_info = event_handler.fetchall()[0]
        # print(user_info[1])
        # print(Hash.hash(args[1]))
        if user_info[1] == Hash.hash(args[1]):
            return (user_info[2], PF.normal_info("login successfully"))
        else:
            return (0, PF.normal_info("wrong password"))
    except:
        return PF.error_info("unexpect")
示例#2
0
def resolve(args):
    if len(args)==1 and args[0]=='help':
        return help_info()
    if len(args)!=3:
        return PF.normal_info("input arguments error, input 'registr help' to get help");

#    if re.search(RE.Re_User_Name,args[0])==None:
#        return PF.normal_info('username fromat is wrong.')
#    if re.search(RE.Re_User_Password,args[1])==None:
#        return PF.normal_info('password fromat is wrong.')
#    if re.search(RE.Re_User_Email,args[2])==None:
#        return PF.normal_info('email fromat is wrong.')
    try:
        sql_connect=pymysql.connect(
            host=SQL.Sql_Host,
            user=SQL.Sql_User,
            passwd=SQL.Sql_Password,
            database=SQL.Sql_Database,
            charset=SQL.Sql_Charset,
            connect_timeout=SQL.Sql_TimeOut
        )
    except:
        return PF.error_info('sql connect error')
    event_handler=sql_connect.cursor()
    query_string=SQL.Sql_Select_User%(args[0])
    #print(query_string)
    if event_handler.execute(query_string):
        return PF.normal_info('user name '+args[0]+' has existed.')
    try:
        time_now=datetime.datetime.now()
        time_now=time_now.strftime('%Y-%m-%d %H:%M:%S')
        # user_id email password reg_time privilege
        query_string=SQL.Sql_Add_User%(args[0],args[2],Hash.hash(args[1]),time_now,1)
        print(query_string)
        event_handler.execute(query_string)
        return PF.normal_info('regist sucessfuly. Pleaee login')
    except:
        return  PF.error_info('unexpect')