def signup(): form = SignupForm(next=request.args.get("next")) if form.validate_on_submit(): user = User() form.populate_obj(user) user.reg_ip = request.remote_addr db.session.add(user) user_icon = Users_icon() db.session.commit() user_icon.uid = user.id db.session.add(user_icon) #默认姓名就是用户名 user.name = user.username #广播一下 queue.push((101,user.id)) db.session.commit() send_msg(user.id,u'欢迎加入42ic.com',u'42ic是一个专注于电子行业的社区网站,欢迎您的加入!') flash(u"您已经注册成功!请登陆", "success") next_url = form.next.data if not next_url or next_url == request.path: next_url = url_for('account.login') #print('OK') return redirect(next_url) return render_template("account/signup.html", form=form)
def user_icon_up_file(): is_login() file = request.files['picfile'] if g.user and file and allowed_file( file.filename ): #user = session.query( Users_icon ).filter_by( uid = uid ).first() #0-9是随机的目录 tmp = str(random.randrange(0,9)) filename = tmp+'/'+str( g.user.id ) + "-" + str( int(time.time()) ) + "." + file.filename.rsplit( '.', 1 )[1] file.save( os.path.join( app.config['AVATAR_IMAGE_PATH'], filename ) ) try: ed_icon = Users_icon.query.filter_by( uid = g.user.id ).first() except: ed_icon = Users_icon() ed_icon.image_name = filename import Image iconname = str( g.user.id ) + "-"+ str( int(time.time()) ) + file.filename.rsplit( '.', 1 )[1] im = Image.open( image_path + "/" + filename ) image2 = pic_square( im, 48 ) image2.save( os.path.join( app.config['AVATAR_PATH'], filename ) ) ed_user = User.query.filter_by( id = g.user.id ).first() ed_user.avatar = filename db.session.commit() flash(u"图片上传成功,请编辑头像。", "success") #清除缓存 cache.delete('session_login_uid_'+str(session['user_id'])) return redirect(url_for("account.user_icon") )