def register_page(): form = UserForm() if session["user_id"]: flash('logout first', category='primary') return redirect('/') if form.validate_on_submit(): username = form.username.data password = form.password.data email = form.email.data first_name = form.first_name.data last_name = form.last_name.data new_user = User.register(username, password, email, first_name, last_name) db.session.add(new_user) try: db.session.commit() except IntegrityError: form.username.errors.append('Username taken. Please pick another') return render_template('register.html', form=form) session["user_id"] = new_user.username flash('Account created successfully!', category='success') return redirect(f'/user/{new_user.username}') else: return render_template("register.html", form=form)
def index(): result = None form = UserForm(request.form) if request.method == 'POST': if form.validate_on_submit(): input_ip_address = request.form['input_ip_address'] result = main_func(input_ip_address) return render_template('find-interface.html', form=form, result=result)
def hello_world(): uform = UserForm() if uform.validate_on_submit(): name = uform.name.data password = uform.password.data phone = uform.phone.data icon = uform.icon.data filename = secure_filename(icon.filename) icon.save(os.path.join(UPLOAD_DIR, filename)) return '提交成功!' return render_template('user.html', uform=uform)
def boot_form_user(): uform = UserForm() if uform.validate_on_submit(): # 主要通过其进行校验 校验提交方式以及form的验证 name = uform.name.data password = uform.password.data phone = uform.phone.data print('name:', name, ' password:'******' phone:', phone) icon = uform.icon.data # FileStorage类型 print(type(icon)) # 构建安全文件名 存入 filename = secure_filename(icon.filename) icon.save(os.path.join(UPLOAD_DIR, filename)) return '提交成功!' return render_template('user1.html', uform=uform)
def update_user_info(): if request.method == 'GET': user = User.query.filter_by(id=current_user.id).first() form = UserForm( username=user.username, nick_name=user.nick_name, ) return render_template('user_update.html', title='用户信息', form=form) form = UserForm() if form.validate_on_submit(): user = User.query.filter_by(id=current_user.id).first() user.username = form.username.data user.nick_name = form.nick_name.data db.session.commit() flash('update user info') return redirect(url_for('get_user_info'))
def edit_user(id): edit_user= User.query.filter_by(id=id).first() form = UserForm(obj=edit_user) if form.validate_on_submit(): try: # Update user form.populate_obj(edit_user) db.session.add(edit_user) db.session.commit() # User info flash('Saved successfully', 'success') return redirect(url_for('users')) except: db.session.rollback() flash('Error update contact.', 'danger') return render_template( 'edit.html', form=form)
def user_signup(): """Create new user and add to database""" form = UserForm() if form.validate_on_submit(): try: user = User.signup( username=form.username.data, password=form.password.data, email=form.email.data ) db.session.commit() except IntegrityError: flash("Username is already taken", 'danger') return render_template('/user/signup.html', form=form) login_user(user, remember=True) return redirect('/') else: return render_template('/user/signup.html', form=form)
def register_user(): form = UserForm() if form.validate_on_submit(): username = form.username.data password = form.password.data email = form.email.data first_name = form.first_name.data last_name = form.last_name.data new_user = User.register(username, password, email, first_name, last_name) db.session.add(new_user) try: db.session.commit() except IntegrityError: form.username.errors.append('Username taken, Please pick another!!!!') return render_template('register.html', form=form) session['username'] = new_user.username flash('Welcome! Successfully create account!!') return redirect(f'/users/{username}') return render_template('register.html', form=form)
def submit(): form = UserForm() #basepath = os.path.dirname(__file__) # 收到表單 if request.method == 'POST': # 抓取時間,格式化後轉成字串 time = datetime.datetime.now() timeStr = time.strftime('%y%m%d%H%M%S') # 檢驗表單資料格式、缺失 if form.validate_on_submit(): # 以 email+datetime 作為filename(需唯一) if request.form.get('email'): email = str(form.email.data) else: email = 'test' filename = email.replace('.', '') + timeStr # 處理textarea if request.form['seqs']: text = request.form['seqs'] # target = os.path.join(os.getcwd(), '/static/uploads/'+filename) fo = open('/home/ubuntu/wpSBOOT/static/uploads/'+filename,'w+') #print("filename :"+filename) fo.write(text) fo.close() elif request.files['file'] : # 處理file儲存 f = request.files['file'] # filename = secure_filename(f.filename) f.save(os.path.join(basepath, 'static/uploads', filename)) else : return redirect(url_for('index')) # create cmd line # -i input cmd_list.append('-i') cmd_list.append('./static/uploads/'+filename) # -o output cmd_list.append('-o') cmd_list.append(filename) # -p path cmd_list.append('-p') cmd_list.append('./static/UserData/'+filename) #print(cmd_list) # 判斷option, aligner selector opcount = 0 #mafft if request.form.get('mafft'): cmd_list.append('-m') cmd_list.append('mafft') opcount += 1 #msucle if request.form.get('muscle'): cmd_list.append('-m') cmd_list.append('muscle') opcount += 1 #clustalw if request.form.get('clustalw'): cmd_list.append('-m') cmd_list.append('clustalw') opcount += 1 #tcoffee if request.form.get('t-coffee'): cmd_list.append('-m') cmd_list.append('tcoffee') opcount += 1 # if the number of aligners less than 2 (fatal error) if opcount < 2: return redirect(url_for('index')) # 執行 cmd line p = subprocess.Popen(cmd_list) p.communicate() #session if email != 'test': session['mail'] = email.replace('.', '') session.permanent = True # Mail link = url_for('result', fid=filename, _external=True) msg = Message( subject='wpSBOOT alignment result', recipients=[email], html='Hello,<br>' '<blockquote>Your alignment has been completed.<br>' 'Please click <a href="{link}">here</a> to view your results.<br><br>' 'If you have question or report problems, do not reply to this message,and write instead to ' '<a href="mailto:[email protected] ">[email protected]</a></blockquote>' '<br>Cheers,<br>' 'wpSBOOT team'.format(link=link) ) mail.send(msg) return redirect(url_for('result', fid=filename)) else: return redirect(url_for('index'))