def login(): if request.method=="GET": return render_template("login.html") else: try: data=json.loads(request.get_data(as_text=True), strict=False) email=data.get("email") pwd=data.get("pass") dict_msg={} result=base.login_check(email,pwd) if type(result) is str: dict_msg={"status":"1002","Msg":result,"value":""} else: session["email"]=email session["uid"]=result.uid session["username"]=result.username if not base.write_logs(result.uid): dict_msg={"status":"1000","Msg":"登录成功","value":"/"} else: dict_msg={"status":"1001","Msg":"登录失败","value":""} except Exception as e: dict_msg={"status":"1003","Msg":str(e),"value":""} logging(email+"登录--->"+dict_msg["Msg"]) return jsonify(dict_msg)
def get(self): args = UserHistoryGetArgs().args if not login_check(session): return None user = get_user(user_id=session['login_user'])[0] history = get_user_history(user, args['start'], args['end']) return marshal(history, history_fields)
def post(self): #import pdb; pdb.set_trace() if login_check(session): return marshal({'status':'already login', 'user_id':None}, app_auth_fields) args = AppAuthArgs().args args['user_name'] = args['user_name'].encode('utf-8') args['password'] = args['password'].encode('utf-8') request_url = APP_AUTH_URL % (args['user_name'], args['password']) r = requests.get(request_url) if r.status_code != requests.codes.ok: return marshal({'status':'can not get rs response', 'user_id':None, 'user_name':None}, app_auth_fields) result = json.loads(r.text) if result['status'] != 'ok': return marshal({'status':result['status'], 'user_id':None, 'user_name':None}, app_auth_fields) session['login_user'] = result['user_id'] #update user table if not user_model.get_user(user_id=result['user_id']): user_model.add_user(result['user_id']) #update login_user table login_user = login_user_model.get_login_user(user_id=result['user_id']) if login_user: login_user_model.delete_login_user(login_user[0]) cookie_key = hashlib.md5(result['user_id']).hexdigest().lower() login_user_model.add_login_user(user_id=result['user_id'], cookie_key=cookie_key, user_name=result['user_name']) return marshal({'status':'success', 'user_id':result['user_id'], 'user_name': result['user_name']}, app_auth_fields)
def post(self): args = UserHistoryPostArgs().args if not login_check(session): return None user = get_user(user_id=session['login_user'])[0] add_user_history(user, args['op'], args['key']) update_login_user_table(session['login_user']) return marshal({'status':args['op'] + '_success'}, status_fields)
def get(self): args = UserMusicQueryArgs().args if not login_check(session): return None user = get_user(user_id=session['login_user'])[0] music_list = get_user_music_list(user, args['type'], args['start'], args['end']) update_login_user_table(session['login_user']) return marshal(music_list, music_fields)
def get(self): ret = {} if not login_check(session): ret['status'] = 'have not login' else: info = 'user %s logout', session['login_user'] login_log.log_info(info) user = get_login_user(user_id=session['login_user'])[0] delete_login_user(user) session.pop('login_user', None) ret['status'] = 'success' return marshal(ret, status_fields)
def get(self): if login_check(session): return marshal({'status': 'user already login', 'authorize_url': None}, oauth_request_fields) request_token = OAuthRequest.get_request() if not request_token: return marshal({'status': 'can not get request_token', 'authorize_url': None}, oauth_request_fields) user_recognition = OAuthRequest.generate_user_recognition(request_token) if not oauth_model.add_oauth(request_token=request_token, user_recognition=user_recognition): return marshal({'status': 'store request token fail', 'authorize_url': None}, oauth_request_fields) session['user_recognition'] = user_recognition authorize_url = AUTHORIZE_URL % (request_token, REDIRECT_URL) return marshal({'status': 'success', 'authorize_url': authorize_url}, oauth_request_fields)
def get(self): if not login_check(session): return None user = get_user(user_id=session['login_user'])[0] return marshal(user, user_fields)