def post(self): # receive args rs_type = self.get_argument('rs_type', 0) # print '======>' + str(rs_type) uname = self.get_argument('uname', '') upass = self.get_argument('upass', '') # init json result rs = {'code' : 1, 'msg' : '', 'result' : []} # args check if len(uname) == 0 or len(upass) == 0: rs['msg'] = INVALID_ARGS self.write(json.dumps(rs)) return # db operations upass_md5 = encode_md5(upass) session = self.backend.get_session() user_profile_dict = {} try: # TODO: u = session.query(User).filter_by(uname=uname).first() # print 'upass: %s' % upass_md5 # print 'u.upass: %s' % u.upass if u is not None and u.upass == upass_md5: rs['code'] = 0 rs['result'].append( {'uname': u.uname, 'upass': upass} ) user_profile = session.query(UserProfile).filter(UserProfile.uid == u.uid).first() user_profile_dict = to_dict(user_profile) # set cookies self.set_secure_cookie('uname', uname) else: rs['msg'] = EMPTY_RESULT except Exception, e: # pass rs['msg'] = str(e).encode('utf-8')
def post(self): # receive args phone = self.get_argument('phone', '') upass = self.get_argument('upass', '') # init json result rs = {'code' : 1, 'msg' : ''} # args check if len(phone) == 0 or len(upass) == 0: rs['msg'] = INVALID_ARGS self.write(json.dumps(rs)) return # db operations upass_md5 = encode_md5(upass) session = self.backend.get_session() try: user = User(uname=phone, phone=phone, upass=upass_md5) print 'uid: %s' % user.uid session.add(user) session.commit() rs['code'] = 0 except Exception, e: rs['msg'] = str(e).encode('utf-8') session.rollback()