def register(request): if request.method == 'POST': form = Register(request.POST, request.FILES) if form.is_valid(): user = Libuser.objects.create( username=form.cleaned_data['username'], first_name=form.cleaned_data['first_name'], last_name=form.cleaned_data['last_name'], email=form.cleaned_data['email'], address=form.cleaned_data['address'], city=form.cleaned_data['city'], province=form.cleaned_data['province'], phone=form.cleaned_data['phone'] ) password = form.cleaned_data['password'] user.profilepic = form.cleaned_data['profilepic'] user.set_password(password) user.save() form = Register() return render(request, 'libapp/register.html', {'form': form, 'added': True}) else: form = Register() return render(request, 'libapp/register.html', {'form': form, 'failed': True}) else: form = Register() return render(request, 'libapp/register.html', {'form': form})
def register(): form = Register() if request.method == 'POST' and form.validate_on_submit(): fname = request.form['fname'] lname = request.form['lname'] password = request.form['password'] allergies = form.allergies.data # Check if account exists using MySQL cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor) cursor.execute('Select AccID from accounts order by length(AccID) DESC,AccID Desc Limit 1') lastid = cursor.fetchone().get("AccID").split('-')[1] id = int(lastid) + 1 print(id) cursor.execute('INSERT INTO accounts (AccID,first_name,last_name,password) VALUES (%s, %s, %s, %s)', ('AC-' + str(id),fname, lname, password,)) for key, value in allergies.items(): if value == True: AllID = key.split('_')[1] print(AllID) cursor.execute('Insert into user_allergies values (%s,%s)',('AC-' + str(id),"AL-" + str(AllID))) mysql.connection.commit() cursor.close() flash('Registration Complete ID is: AC-' + str(id)) return redirect(url_for('login')) return render_template('register.html',form=form)
def register(): form = Register() if form.validate_on_submit(): email_check = Student.query.filter_by(email=form.email.data).first() if email_check != None: flash( 'This email is already assigned to a student. Are you sure you are not already a student at this school?' ) return render_template('student_templates/register.html', form=form) # work around so that user loader doesn't get confused count1 = Student.query.order_by(Student.id.desc()).all()[0].id count2 = Teacher.query.order_by(Teacher.id.desc()).all()[0].id id = max(count1, count2) + 1 new_student = Student(id=id, first_name=form.first_name.data.title(), last_name=form.last_name.data.title(), email=form.email.data, birthday=form.birthday.data, grade=int(form.grade.data), pic_url=form.pic_url.data, password_hash=generate_password_hash( form.password.data)) if len(form.twitter.data) > 0: new_student.twitter = form.twitter.data db.session.add(new_student) db.session.commit() flash( f'Thank you {new_student.first_name} {new_student.last_name}. You are now a registered student! Please Log in!' ) return redirect('/login') return render_template('student_templates/register.html', form=form)
def register(): form = Register() if form.validate_on_submit(): # form.validate_email(form.email.data) # form.validate_username(form.username.data) # 根据表单数据 创建用户对象 u = User(username=form.username.data, password=form.password.data, emil=form.email.data) # 把用户信息保存到数据库 db.session.add(u) # 发送账户激活邮件 # 标识身份数据 s = Serializer(current_app.config['SECRET_KEY']) # 当前用户id为空,要手动提交 db.session.commit() token = s.dumps({'id': u.id}) send_mail('账户激活', u.emil, 'email/ectivate.html', username=u.username, token=token) flash('您已经注册成功,请点击邮件中链接进行激活!') return redirect(url_for('main.index')) return render_template('user/register.html', form=form)
def register(): register = None form = Register() if form.validate_on_submit(): username = form.username.data password = form.password.data password2 = form.password2.data register = register_account(username, password, password2) return render_template('register.html', form=form, register=register)
def register(): if current_user.is_authenticated: return redirect(url_for('Convert')) if request.method == 'GET': form = Register() return render_template('register.html', form = form) # Validate file upload on submit form = Register() if request.method == 'POST' and form.validate_on_submit(): # Get file data and save to your uploads folder Fname = form.firstname.data Lname = form.lastname.data Email = form.email.data Password = form.password.data user =User(Fname,Lname,Email,Password) db.session.add(user) db.session.commit() return redirect(url_for('login')) return render_template('register.html', form=form)
def register(request): #insert cookie logic for persistence set_browser_session(request) if request.method == "POST": form = Register(request.POST) if form.is_valid(): data = form.cleaned_data if db.no_user(data['username'], data['email_address']): #pr,pu = crypto.gen_key_pair() passwd = str(data['password']) key = crypto.key_from_pass(passwd, crypto.gen_salt(), crypto.ITER_100K, crypto.KEY_256) o = dict(data) o['secret'] = key o['otp_salt'] = crypto.gen_otp_secret() db.save_user(o) store = dict() store['site'] = "MABEBA Website" store['username'] = str(data['username']) store['token_url'] = PRODUCTION_URL + '/token/' store['secret'] = key store['otp_salt'] = o['otp_salt'] salt = crypto.gen_salt() key = crypto.key_from_pass(passwd, salt, crypto.ITER_100K, crypto.KEY_256) key = crypto.key_to_bytes(key) encrypted = crypto.aes_encrypt(str(store), key) random_id = crypto.get_random_id() db.store_in_file(encrypted, random_id) o = dict() o['salt'] = salt o['token'] = PRODUCTION_URL + '/register/token/' + random_id o = json.dumps(o) print o data = qr_render(o) return render(request, 'app/qr.html', {'data': data}) else: return do_register(request) else: return do_register(request) else: return do_register(request)
def dispatch_request(self): form = Register(request.form) if form.validate_on_submit(): usr = models.User(username=form.username.data) db.session.add(usr) db.session.commit() user = db.session.query(models.User).filter_by(username=form.username.data).first() login_user(user) return redirect(url_for('login')) session['new-user'] = json.dumps(form.errors) return redirect(url_for('login'))
def register(): form = Register() if request.method == 'GET': return render_template('register.html', form=form) elif request.method == 'POST': new_user = User(username=form.username.data, email=form.email.data, sex=form.sex.data) new_user.set_password(form.password.data) db.session.add(new_user) db.session.commit() return redirect(url_for('login'))
def register(): form = Register() # print(form.validate_on_submit()) if form.validate_on_submit(): user_name = request.form.get('username', None) password = request.form.get('password', None) email = request.form.get('email', None) if handlers.register(user_name, password, email): return redirect(url_for('login')) else: flash('register fail') return redirect(url_for('register')) return render_template('register.html', title='Register', form=form)
def register(): form = Register() if form.validate_on_submit(): verify_code = form.verify_code.data username = User.query.filter_by(username=form.username.data).first() email = User.query.filter_by(email=form.email.data).first() print(verify_code) if username: flash('该账户已经注册') if email: flash('该邮箱已经绑定,请换一个') if re.compile(verify_code, re.I).findall(session['verifyCode']): flash('验证码正确') # 获取上传文件的后缀 suffix = os.path.splitext(form.icon.data.filename)[1] # 生成新的头像名字 name = randStr() + suffix photos.save(form.icon.data, name=name) # 在指定路径生成文件 pathName = os.path.join(current_app.config['UPLOADED_PHOTOS_DEST'], name) # 打开文件 img = Image.open(pathName) # 设置尺寸 img.thumbnail((64, 64)) # 保存缩略图 img.save(pathName) # 创建用户 u = User(username=form.username.data, password=form.password.data, email=form.email.data, icon=name) # 保存数据到数据库 db.session.add(u) # 手动提交到数据库 db.session.commit() # 发送激活邮件到邮箱 token = u.generate_activate_token() send_mail(form.email.data, '账户激活', 'email/activate', token=token, username=form.username.data) flash('激活邮件已发送,请激活') return redirect(url_for('main.index')) else: flash('验证码错误') return render_template('user/register.html', form=form)
def dispatch_request(self): if current_user.is_authenticated: try: user = db.session.query(models.User).filter_by(id=current_user.username).first().username except Exception: logout_user() return redirect(url_for('login')) return render_template('login.html', user=user) else: register_form = Register() login_form = Login() register_errors = json.loads(session.get('new-user', '{}')) login_errors = json.loads(session.get('come-in-user', '{}')) session.pop('new-user', None) session.pop('come-in-user', None) return render_template('login.html', register_form=register_form, login_form=login_form, register_errors=register_errors, login_errors=login_errors)
def register(): form = Register() if form.validate_on_submit(): user ={ 'name': form.name.data, 'email': form.email.data, 'password': form.password.data, 'confirm_password': form.confirm_password.data, } if len(user['password']) < 8: print('1') flash('La contraseña debe contener por lo menos 8 caracteres', 'error') elif user['password'] == None: print('2') flash('Contraseña no valida', 'error') elif user['password'] != user['confirm_password']: print('3') flash('Las contraseñas no coinciden', 'error') return redirect(url_for('auth.register')) else: user_doc = get_user(user['email']) if user_doc.to_dict() is None: password_hash = generate_password_hash(user['password']) user_data = UserData(user['name'], user['email'], password_hash) create_user(user_data) user = UserModel(user_data) login_user(user) flash('Que bueno verte de nuevo!', 'success') return redirect(url_for('auth.login')) else: flash('El usuario ya existe', 'error') return render_template('register.html', form=form)
def register(): form = Register() if form.validate_on_submit(): # 实例化user u = User(username=form.username.data, password=form.password.data, email=form.email.data) db.session.add(u) db.session.commit() # 生成token token = u.generate_token() # 发送邮件 send_mail('邮件激活', form.email.data, 'activate', username=form.username.data, token=token) # 提示注册 flash('注册成功,去激活') # 跳转登陆页面 return redirect(url_for('user.login')) return render_template('user/register.html', form=form)
def register(): # code = random.randrange(1000, 10000) # 生成随机验证码 error_msg = None success = None form = Register() if current_user.is_authenticated: return redirect(url_for('admin.inded_select')) elif request.method == 'GET': phone_number = request.args.get('mobile_phone_number') # phone_number = form.tel.data if phone_number is not None: if ali_sms.send_sms(phone_number, ali_sms.code): return render_template('forms.html', error_msg=error_msg, form=form) else: error_msg = 'Failed to get the verification code!' elif form.validate_on_submit(): tel = form.tel.data v_code = form.v_code.data password = form.password1.data if ali_sms.verify_code(v_code, ali_sms.code): # if 1: user = User(Tel_Number=tel) user.set_password(password) db.session.add(user) db.session.commit() return redirect(url_for('login.back_login')) else: error_msg = '验证码不正确,请检查' return render_template('use_templates/c_register.html', error_msg=error_msg, form=form) return render_template('use_templates/c_register.html', form=form)
def do_register(request): form = Register() return render(request, 'app/register.html', {'register_form': form})