def insert_UserCollection_image(self,list,ucid): db = get_db() for picurl in list: try: isexist = db.query(UserCollectionimg).filter(UserCollectionimg.UCIurl==picurl,UserCollectionimg.UCIuser == ucid).one() isexist.UHpicvalid = 1 db.commit() except Exception, e:#未找到该图片 print'插入单张新图片' image = Image( IMvalid=True, IMT=time.strftime('%Y-%m-%d %H:%M:%S'), IMname=picurl ) db.merge(image) db.commit() auth = AuthKeyHandler() sizedata = auth.getsize(picurl) new_img = get_db().query(Image).filter(Image.IMname == picurl).all() imid = new_img[0].IMid new_ucimg=UserCollectionimg( UCIuser=ucid, UCIimid=imid, UCIurl=picurl, UCIvalid=1, UCIheight=sizedata['height'], UCIwidth=sizedata['width'], ) db.merge(new_ucimg) db.commit()
def insert(self, list): ''' 向数据库插入图片链接 :param list: 图片名的列表 :table: 应该插入的表名 :return: ''' new_imids = [] for img_name in list: # 第一步,向Image里表里插入 image = Image(IMvalid=True, IMT=time.strftime('%Y-%m-%d %H:%M:%S'), IMname=img_name) db = get_db() db.merge(image) db.commit() new_img = get_db().query(Image).filter( Image.IMname == img_name).one() imid = new_img.IMid new_imids.append(imid) return new_imids
def insert(self, list): db = get_db() new_imids = [] for img_name in list: # 第一步,向Image里表里插入 image = Image( IMvalid=True, IMT=time.strftime('%Y-%m-%d %H:%M:%S'), IMname=img_name, ) db.merge(image) db.commit() try: new_img = get_db().query(Image).filter( Image.IMname == img_name).one() imid = new_img.IMid new_imids.append(imid) except Exception, e: print e
def insert_Homepage_image(self, list, uid): try: db = get_db() userinfo = db.query(User).filter(User.Uid == uid).one() for picurl in list: try: isexist = db.query(UserHomepageimg).filter( UserHomepageimg.UHpicurl == picurl, UserHomepageimg.UHuser == userinfo.Uid).one() isexist.UHpicvalid = 1 db.commit() except Exception, e: # 单张图片插入 image = Image(IMvalid=True, IMT=time.strftime('%Y-%m-%d %H:%M:%S'), IMname=picurl) db.merge(image) db.commit() auth = AuthKeyHandler() try: # 获取图片大小的Json对象 sizedata = auth.getsize(picurl) new_img = get_db().query(Image).filter( Image.IMname == picurl).one() imid = new_img.IMid new_hpimg = UserHomepageimg( UHuser=userinfo.Uid, UHimgid=imid, UHpicurl=picurl, UHpicvalid=True, UHheight=sizedata['height'], UHwidth=sizedata['width'], ) db.merge(new_hpimg) db.commit() except Exception, e: print e
def get(self): callback = self.get_argument("jsoncallback") type = self.get_argument('type', default='unsolved') if type == '10001': # 验证手机号 m_phone=self.get_argument('phone') try: utel = base64.encodestring(m_phone) utel = utel.replace('\n','') user = self.db.query(User).filter(User.Utel == utel).one() if user: self.retjson['contents'] = u"该手机号已经被注册,请更换手机号或直接登录" self.retjson['code'] = 10005 except: code=generate_verification_code() veri=Verification( Vphone=m_phone, Vcode=code, ) self.db.merge(veri) try: self.db.commit() self.retjson['code'] = 10004 # success self.retjson['contents'] = u'手机号验证成功,发送验证码' except: self.db.rollback() self.retjson['code'] = 10009 # Request Timeout self.retjson['contents'] = u'服务器错误' message(code, m_phone) elif type=='10002': #验证验证码 m_phone=self.get_argument('phone') code=self.get_argument('code') try: item=self.db.query(Verification).filter(Verification.Vphone==m_phone).one() #exist = self.db.query(Verification).filter(Verification.Vphone == m_phone).one() #delta = datetime.datetime.now() - exist.VT if item.Vcode==code: #if delta<datetime.timedelta(minutes=10): self.retjson['code']=10004 self.retjson['contents']=u'验证码验证成功' #else : #self.retjson['code'] = 10006 #self.retjson['contents'] = u'验证码验证失败' else: self.retjson['code']=10006 self.retjson['contents']=u'验证码验证失败' except: self.retjson['code']=10007 self.retjson['contents']=u'该手机号码未发送验证码' elif type=='10003': #注册详细信息 m_password=self.get_argument('password') m_nick_name=self.get_argument('nickName') # 昵称 m_phone=self.get_argument('phone') m_sex = self.get_argument('sex') #性别 try: m_phone = base64.encodestring(m_phone) m_phone = m_phone.replace("\n","") m_password = md5(m_password) same_nickname_user = self.db.query(User).filter(User.Uname == m_nick_name).one()#临时判断 if same_nickname_user: # 该昵称已被使用 self.retjson['code'] = '10008' # Request Timeout self.retjson['contents'] ="该昵称已被使用" except: # 手机号和昵称皆没有被注册过 new_user = User( Upassword=m_password, Ualais=m_nick_name, Utel=m_phone, Usex=m_sex, ) self.db.merge(new_user) try: self.db.commit() image = Image( IMvalid=True, IMT=time.strftime('%Y-%m-%d %H:%M:%S'), IMname=m_nick_name ) self.db.merge(image) self.db.commit() m_id = self.db.query(User.Uid).filter(User.Utel == m_phone).one() new_img = self.db.query(Image).filter(Image.IMname == m_nick_name).one() imid = new_img.IMid userImage = UserImage( UIuid = m_id[0], UIimid = imid, UIurl = "user-default-image.jpg" ) self.db.merge(userImage) self.db.commit() # self.retjson['contents'] = retdata new_choosed_entry = NewChoosed( uid=user.Uid, choosed=0 ) self.db.merge(new_choosed_entry) try: self.db.commit() except Exception, e: self.retjson['code'] = '500' self.retjson['contents'] = u'数据库提交失败' self.retjson['contents'] = m_phone self.retjson['code'] = 10004 # success except Exception, e: print e self.db.rollback() self.retjson['code'] = 10009 # Request Timeout self.retjson['contents'] = u'Some errors when commit to database, please try again'
def post(self): type = self.get_argument('type', default='unsolved') if type == '10001': # 验证手机号 m_phone = self.get_argument('phone') try: user = self.db.query(User).filter(User.Utel == m_phone).one() if user: self.retjson['contents'] = u"该手机号已经被注册,请更换手机号或直接登录" self.retjson['code'] = 10005 except: code = generate_verification_code() veri = Verification( Vphone=m_phone, Vcode=code, ) self.db.merge(veri) try: self.db.commit() self.retjson['code'] = 10004 # success self.retjson['contents'] = u'手机号验证成功,发送验证码' except: self.db.rollback() self.retjson['code'] = 10009 # Request Timeout self.retjson['contents'] = u'服务器错误' message(code, m_phone) elif type == '10002': #验证验证码 m_phone = self.get_argument('phone') code = self.get_argument('code') try: item = self.db.query(Verification).filter( Verification.Vphone == m_phone).one() #exist = self.db.query(Verification).filter(Verification.Vphone == m_phone).one() #delta = datetime.datetime.now() - exist.VT if item.Vcode == code: #if delta>datetime.timedelta(minutes=10): self.retjson['code'] = 10004 self.retjson['contents'] = u'验证码验证成功' else: self.retjson['code'] = 10006 self.retjson['contents'] = u'验证码验证失败' except: self.retjson['code'] = 10007 self.retjson['contents'] = u'该手机号码未发送验证码' elif type == '10003': #注册详细信息 m_password = self.get_argument('password') m_nick_name = self.get_argument('nickName') # 昵称 m_phone = self.get_argument('phone') m_auth_key = generate_auth_key() retdata = [] retdata_body = {} new_user = User( Upassword=m_password, Ualais=m_nick_name, Uname='', Ulocation='', # 新用户注册默认level为1 Umailbox='', Ubirthday='2000-01-01 00:00:00', Utel=m_phone, Uscore=0, Usex=1, Usign='', Uauthkey=m_auth_key, Uchattoken='') try: same_nickname_user = self.db.query(User).filter( User.Ualais == m_nick_name).one() if same_nickname_user: # 该昵称已被使用 data = user_login_fail_model() retdata_body['userModel'] = data retdata.append(retdata_body) self.retjson['code'] = '10008' # Request Timeout self.retjson['contents'] = retdata except: # 手机号和昵称皆没有被注册过 self.db.merge(new_user) try: self.db.commit() m_time = self.db.query(User.UregistT).filter( User.Uauthkey == m_auth_key).one() m_id = self.db.query( User.Uid).filter(User.Uauthkey == m_auth_key).one() user = self.db.query(User).filter( User.Uauthkey == m_auth_key).one() m_token = get_token(user.Uid, user.Ualais) user.Uchattoken = m_token image = Image(IMvalid=True, IMT=time.strftime('%Y-%m-%d %H:%M:%S'), IMname=m_nick_name) self.db.merge(image) self.db.commit() new_img = self.db.query(Image).filter( Image.IMname == m_nick_name).one() imid = new_img.IMid userImage = UserImage(UIuid=m_id[0], UIimid=imid, UIurl="user-default-image.jpg") self.db.merge(userImage) self.db.commit() rank_list_handler = RanklistHandler() rank_list_handler.insert_new_rank(m_id[0]) #auth = AuthKeyHandler() # data=dict( # phone = m_phone, # authkey = m_auth_key, # nickName = m_nick_name, # headImage =auth.download_url("user-default-image.jpg"), # realName ='', # birthday ='', # sign ='', # score ='', # location ='', # registTime ='', # mailbaox = '', # id = m_id[0], # chattoken = m_token # ) # retdata_body['userModel'] =data # login = LoginHandler() # retdata_body['daohanglan']=login.bannerinit() # retdata.append(retdata_body) try: u_info = UCinfo(UCuid=m_id[0], UClikeN=0, UClikedN=0, UCapN=0, UCphotoN=0, UCcourseN=0, UCmomentN=0) self.db.merge(u_info) self.db.commit() except Exception, e: print e self.retjson['contents'] = r'初始化用户信息时出错' # ucinfo插入失败 # self.retjson['contents'] = retdata self.get_new_login_model(user) self.retjson['code'] = 10004 # success except Exception, e: print e self.db.rollback() self.retjson['code'] = 10009 # Request Timeout self.retjson[ 'contents'] = 'Some errors when commit to database, please try again :{}'.format( e)