Пример #1
0
def auth_user():
    if config.RUN_METHOD == "sso":
        url = request.url
        sso_userinfo = auth_sso()
        if not sso_userinfo:
            redirect_url = "/sso?redirect_url=" + url
            return [False, redirect_url]
        else:
            local_userinfo = Userinfo.get_userinfo_by_username(sso_userinfo['username'])
            if not local_userinfo:
                redirect_url = config.SSO_WEBSITE
                return [False, redirect_url]
            else:
                userinfo = {}
                userinfo['user_id'] = local_userinfo[0]
                userinfo['username'] = local_userinfo[1]
                userinfo['chinese_name'] = sso_userinfo['chinese_name']
                return [True, userinfo]
    else:
        if 'user_id' in session:
            user_id = session['user_id']
            local_userinfo = Userinfo.get_userinfo_by_user_id(user_id)
            userinfo = {}
            userinfo['user_id'] = user_id
            userinfo['username'] = local_userinfo[1]
            return [True, userinfo]
        else:
            return [False, "/account/login"]
Пример #2
0
def check_login_lib(username, md5_password):
    userinfo = Userinfo.get_userinfo_by_username(username)
    if not userinfo:
        return False
    if userinfo[2] == md5_password:
        return True
    else:
        return False
Пример #3
0
def login_api():
    tmp_dict = {}
    tmp_dict['success'] = "false"
    set_cookie = 0
    if request.method == "POST":
        try:
            username = request.form['username']
            password = request.form['password']
            h=hashlib.md5()
            h.update(password)
            md5_password=h.hexdigest()
            if check_login_lib(username, md5_password):
                userinfo = Userinfo.get_userinfo_by_username(username)
                session['user_id'] = userinfo[0]
                tmp_dict['success'] = "true"
            else:
                tmp_dict['msg'] = "username or password error"
        except Exception,e:
            print e
            tmp_dict['msg'] = "no post data"