def singup(request): if request.method == 'POST': form = forms.RegistrationForm(data=request.POST) if form.is_valid(): form.save() data = form.cleaned_data user = auth.authenticate(username=data['username'], password=data['password1']) if user is not None: auth.login(request, user) formAv = AvatarForm(request.user, request.POST, request.FILES) if formAv.is_valid(): formAv.save() return redirect('/main/') if request.method == 'GET': form = forms.RegistrationForm formAv = AvatarForm(request.user) tags = Tag.objects.best_tags()[0:10] users = Client.objects.best_members()[0:10] return render(request, 'sing_up_page.html', { 'tags': tags, 'users': users, 'form': form, 'formAv': formAv, 'user': request.user, 'errors': form.errors, })
def test_register_form_validate(client): from app import forms rs = forms.RegistrationForm() rs.validate() rs.check_initial_validation(True) rs.check_email_registered("*****@*****.**") rs.check_username_registered("admin")
def register(): if current_user.registered and not current_user.deleted: return redirect(url_for('match')) form = forms.RegistrationForm(request.form) if request.method == 'POST' and form.validate(): user = current_user user.username = form.username.data user.allow_reddit_notifications = form.allow_reddit_notifications.data user.bio = form.bio.data user.newsletter = True user.registered = True user.created_on = datetime.datetime.now() user.email_verified = False if form.email.data: user.email = form.email.data else: user.email = None favorite_subs = [] favorite_subs.append(form.favorite_sub_1.data.lower()) if form.favorite_sub_2.data: favorite_subs.append(form.favorite_sub_2.data.lower()) if form.favorite_sub_3.data: favorite_subs.append(form.favorite_sub_3.data.lower()) user.unfavorite_all() for sub in favorite_subs: # strip /r/ from name if '/' in sub: sub = sub.split('/')[-1] if models.Subreddit.query.filter_by(name = sub).first() is None: subreddit = models.Subreddit(name=sub) db.session.add(subreddit) db.session.commit() user.favorite(subreddit) else: subreddit = models.Subreddit.query.filter_by(name = sub).first() user.favorite(subreddit) db.session.commit() return redirect(url_for('match')) form.allow_reddit_notifications.default = True form.process() return render_template('register.html', title='Reddimatch - Register', form=form, page_class='register_page')
def registration(): if current_user.is_authenticated: return redirect(url_for('index')) form = forms.RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash('Вы были успешно зарегестрированы.') return redirect(url_for('index')) return render_template('registration.html', form=form)
def register(): form = forms.RegistrationForm(request.form) if request.method == 'POST' and form.validate(): main_info = [ form.room_type.data, form.reason.data, form.first_name.data, form.last_name.data, form.middle_name.data, form.birthday.data, form.department.data, form.specialty.data, form.group.data, form.work.data, form.s_passport.data, form.n_passport.data, form.d_passport.data, form.k_passport.data, form.phone_number.data, form.lived_hostel.data, form.lived_room.data, form.form_of_education.data, form.email.data ] main_info = [None if x == '' else x for x in main_info] main_info = models.Register_main(*main_info) db_session.add(main_info) db_session.commit() if form.family_radio.data == 'y': main_family = [ main_info.id, form.husband_wife.data, form.husband_wife_work.data, form.husband_wife_birthday.data, form.husband_wife_s_passport.data, form.husband_wife_n_passport.data, form.husband_wife_d_passport.data, form.husband_wife_k_passport.data, form.husband_wife_form_of_education.data, form.husband_wife_lived.data, form.husband_wife_lived_hostel.data, form.husband_wife_lived_room.data, form.childrens.data, form.children_live.data ] main_family = [None if x == '' else x for x in main_family] db_session.add(models.Register_family(*main_family)) db_session.commit() elif form.family_radio.data == 'n': main_student = [ main_info.id, form.father.data, form.father_work.data, form.mother.data, form.mother_work.data, form.brothers_sisters.data, form.parents_street.data, form.parents_home.data, form.parents_apartment.data, form.parents_settlement.data, form.parents_district.data, form.parents_region.data, form.parents_index.data, form.parents_landline_phone.data, form.parents_mobile_phone.data ] main_student = [None if x == '' else x for x in main_student] db_session.add(models.Register_student(*main_student)) db_session.commit() flash('Thanks for registering') return redirect(url_for('index')) return render_template('register.html', form=form)
def register_adm(): if current_user.is_authenticated: return redirect('/') form = forms.RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() return redirect('/adm') return render_template('registration.html', form=form, title='say something')
def register(): # 验证当前用户是否验证 if current_user.is_authenticated: return redirect(url_for('index')) form = forms.RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash('恭喜您成为我们网站的新用户') return redirect(url_for('login')) return render_template('register.html', title='注册', form=form)
def registration(): form = forms.RegistrationForm() if form.validate_on_submit(): user = models.User( email=form.email.data, password=form.password.data, other=form.other.data ) db.session.add(user) db.session.commit() flash("New user has been registered") return render_template('registration.html', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('index')) form = forms.RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data) user.set_password(form.password.data) if "whitemountainscience.org" in user.email: user.wmsi_user = True user.data_story = True # only for testing, this should be more secure db.session.add(user) db.session.commit() flash('Congratulations, you are now a registered user!') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def register(): form = forms.RegistrationForm() if form.validate_on_submit(): app.logger.info('Start of Registering the user') app.logger.warning(form.username.errors) app.logger.warning(form.email.errors) username = form.username.data email = form.email.data password = form.password.data user = User(username=username, email=email) user.set_password(password) db.session.add(user) db.session.commit() flash(f'{username} had registered successfully ! ') app.logger.info(f'{username} has registered successfully!') return redirect(url_for('login')) return render_template('register.html', form=form, title='Register')
def register_new_user(): if not request.json: return make_response(jsonify({'error': 'application/json expected'}), 400) form = forms.RegistrationForm(csrf_enabled=False) form.email = request.json.get('email') form.password = request.json.get('password') form.other = request.json.get('other') if form.validate(): user = models.User( email=request.json['email'], password=request.json['password'], other=request.json.get('other') ) db.session.add(user) db.session.commit() return make_response(jsonify({'status': 'success'}), 201) else: return make_response(jsonify(form.errors), 400)
def account(): reg_form = forms.RegistrationForm() new_acc_form = forms.newAccountForm() #check if registration form was submitted if reg_form.submit_reg.data and reg_form.validate_on_submit(): current_app.database.registration(reg_form.username.data, reg_form.password.data) return redirect(url_for('account')) #check if new telegram acc form was submitted if new_acc_form.submit_acc.data and new_acc_form.validate_on_submit(): api_keys = current_app.database.get_api_keys() api_id, api_hash = api_keys['api_id'], api_keys['api_hash'] #create new TelegramClient for this number and request activation try: data = new_acc_form.data unique_key = str(uuid4()) client = TelegramClient(unique_key, api_id, api_hash) clients_list[data['phone']] = client #creating another process in case of laggs request_sign_in(data['phone']) current_app.database.add_account(new_acc_form.data, unique_key) except: clients_list.pop(data['phone'], None) flash('Some error occured, try again.', 'registration error') pass return redirect(url_for('account')) #activating or removing account if request.form: if request.form.get('action', None) == 'Activate' and request.form['code'] != '': #activating account through TelegramClient that we created earlier for this number client = clients_list.get(request.form['phone'], None) if client == None: flash('Some error with activation.', 'activating error') client.disconnect() else: try: # connect and use given code client.connect() client.sign_in(code=request.form['code']) time.sleep(0.5) if not client.is_user_authorized(): # authorization failed client.disconnect() raise Exception( "Looks like there was a wrong code? user not authorized." ) client.disconnect() # if it is ok, add account to db current_app.database.activate_account( request.form['phone']) clients_list.pop(request.form['phone'], None) except Exception as e: print(e) client.disconnect() flash('Wrong code or some error occured.', 'activating error') # user requested deleting of acc elif request.form.get('action', None) == 'Remove': current_app.database.del_account(request.form['phone']) all_accounts = [ account for account in current_app.database.get_accounts_list() ] return render_template('account.html', reg_form=reg_form, new_acc_form=new_acc_form, all_accounts=all_accounts)