def register(): form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): try: usrQuery = User.objects.get(uname=form.data['uname']) if usrQuery is not None: flash('Username already exists!') redirect(url_for('profile.register')) else: usr = User(uname=form.uname.data, fname=form.fname.data, lname=form.lname.data, email=form.email.data, gender=form.gender.data, pwd=form.pwd.data, dscrp=form.dscrp.data, bday=form.bday.data, creation_date=datetime.now()) usr.save() flash('Thanks for registering!') return redirect(url_for('login.login')) except User.DoesNotExist: usr = User(uname=form.uname.data, fname=form.fname.data, lname=form.lname.data, email=form.email.data, gender=form.gender.data, pwd=form.pwd.data, dscrp=form.dscrp.data, bday=form.bday.data, creation_date=datetime.now()) usr.save() flash('Thanks for registering!') return redirect(url_for('login.login')) return render_template('register.html', form=form)
def registro(): form = RegisterForm() if form.validate_on_submit(): nombre = form.nombre.data print nombre form.nombre.data = 'Es otro german' return render_template
def register_user(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): login = form.cleaned_data['login'] passwd = form.cleaned_data['passwd'] name = form.cleaned_data['name'] #birthday = form.cleaned_data['birthday'] city = form.cleaned_data['city'] region = form.cleaned_data['region'] email = form.cleaned_data['email'] md5 = hashlib.md5() md5.update(passwd.encode('utf8')) passwd = md5.hexdigest() user = RPUser(login=login, password_md5=passwd, name=name, role='user', region=region, city=city, email=email, balance=INIT_BALANCE) accept_code = str(uuid.uuid4()) # sessions registration mechanism is not worked on some FF versions :( #request.session['unaccepted_user'] = user #request.session['accept_code'] = accept_code MEM_SESSIONS[accept_code] = (datetime.now(), user) send_activating_letter(email, login, accept_code) return inform_message(_(u'Ваш аккаунт успішно створено! Інструкцію з активації відправлено Вам на e-mail адресу %(email)s') % {'email': email.encode('utf8')}) else: form = RegisterForm() return render_to_response('register.html',{'reg_form':form})
def register_action(request): form = RegisterForm(request.POST) if form.is_valid(): data = form.cleaned_data if request.META.has_key('HTTP_X_FORWARDED_FOR'): ip = request.META['HTTP_X_FORWARDED_FOR'] else: ip = request.META['REMOTE_ADDR'] time_now = datetime.now() username = data['username'] nickname = data['nickname'] password = data['password'] email = data['email'] user_profile_ip = UserProfile.objects.filter(ip=ip).order_by('-time') if len(user_profile_ip) == 0 or time_now - user_profile_ip[0].time > timedelta(days=1): user = User.objects.create_user(username=username, password=password, email=email) if user is not None: user_profile = UserProfile.objects.create(user=user, ip=ip, time=time_now, nickname=nickname) user.save() user_profile.save() user = authenticate(username=username, password=password) auth_login(request, user) return render_to_response('result.jinja', {'state':'1', 'message':u'注册成功', 'url':'/'}, RequestContext(request)) else: return render_to_response('result.jinja', {'state':'2', 'message':u'当前用户名已存在', 'url':'/account/register'}, RequestContext(request)) else: return render_to_response('result.jinja', {'state':'2', 'message':u'相同ip24小时只能注册一次', 'url':'/account/register'}, RequestContext(request)) else: for field in form: if field.errors: return render_to_response('result.jinja', {'state':'2', 'message':field.errors, 'url':'/account/register'}, RequestContext(request))
def register(): if request.method == 'GET': form = RegisterForm() return render_template('register_form.html', form=form, title='Register', no='ar') elif request.method == 'POST': form = RegisterForm(request.form) if form.validate(): if models.Users.create_user(form): flash('You were successfully registered', 'text-success') msg = Message('Login Credentials for fynance.herokuapp.com', sender='', recipients=[str(form.email.data)]) msg.body = """ Kindly use the following username and password to log in to you fynance account Username: %s Password: %s Regard, Ibrahim Jarif """ % (str(form.email.data), str(form.password.data)) print msg.body mail.send(msg) return redirect(url_for('index')) else: return render_template('register_form.html', form=form) else: return render_template('register_form.html',form=form) return render_template('apology.html', message=['Something went wrong'])
def register(request): errors = [] schools = School.objects.all() if request.method=="POST": form = RegisterForm(data = request.POST) if form.is_valid(): username=form.cleaned_data["username"] users = User.objects.filter(username__iexact=username) if not users: email=form.cleaned_data["email"] password=form.cleaned_data["password"] user=User.objects.create_user(username,email,password) if user is not None: user.save() profile = UserProfile() profile.user = user profile.mobile = form.cleaned_data["mobile"] profile.classes = Classes.objects.get(pk=request.POST['classesid']) profile.save() success = _login(request,username, password) if success: if request.POST['next']: return HttpResponseRedirect(request.POST['next']) else: return HttpResponseRedirect('/') else: errors += [_("Sorry, that's not a valid username or password")] else: errors += [_("Sorry, create user failed.")] else: errors += [_("Sorry, user has been existed.")] else: form = RegisterForm() return render_to_response("accounts/register.html",{'form':form, 'errors':errors, 'schools': schools },context_instance=RequestContext(request))
def create(request): form = RegisterForm(request.POST) if not form.is_valid(): return render(request, 'register_form.html', {'form' : RegisterForm()}) obj = form.save() content_type = ContentType.objects.get_for_model(MyUser) type_user = form.cleaned_data['permissions'] codename = '' if type_user == 'S': codename = 'student' elif type_user == 'T': codename='teacher' elif type_user == 'D': codename='desk' else : codename='administration' permission = permission = Permission.objects.get(content_type=content_type, codename=codename) obj.user_permissions.add(permission) if codename == 'administration': permission = Permission.objects.get(content_type=content_type, codename='desk') obj.user_permissions.add(permission) return HttpResponseRedirect('/register/%d/' % obj.pk)
def register(): error = None form = RegisterForm() next = get_redirect_target() next = retain_before_auth_page(next) if request.method == 'POST': if request.form['submit'] == 'cancel': return redirect_back('index') else: if form.validate_on_submit(): user = User( username=form.username.data, email=form.email.data, password=bcrypt.generate_password_hash(form.password.data) ) db.session.add(user) db.session.commit() """" if not form.email.data: user=User.query.filter_by(username=form.username.data).first() user.email = 'defaultemail_' + str(user.id) + '@gmail.com' db.session.add(user) db.session.commit() """"" login_user(user) flash('You were logged in. ', 'success') return redirect_back('index') else: flash('Invalid email or password.', 'danger') return render_template('register.html', form=form, error=error, next=next) else: return render_template('register.html', form=form, error=error, next=next)
def register(): form = RegisterForm() if request.method == 'POST': if not form.validate_on_submit(): flash('Invalid name or/and password', 'danger') return _render_template('join.html', form=form) r = requests.put(api_url + '/user', headers=headers, data=json.dumps({'username': form.username.data, 'password': form.password.data})) # Successfully registration if r.status_code == 201: r = requests.get(api_url + '/token', headers=headers, auth=(form.username.data + '@' + cfg.AppConfig['MAIL_DOMAIN'], form.password.data)) data = json.loads(r.text) session['user'] = User(id=data['id'], username=data['username'], token=data['token']).__dict__ return redirect(url_for('get_all_mails')) # Errors flash(json.loads(r.text)['error'], 'danger') return _render_template('join.html', form=form) else: return _render_template('join.html', form=form)
def _register(request): if REGISTER_TURN_OFF: return render('register_turn_off.html', RequestContext(request)) if request.user.is_authenticated(): auth.logout(request) if request.method == 'GET': form = RegisterForm() return render('register.html', RequestContext(request, {'form': form})) if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): data = form.clean() if data['password'] != data['re_password']: return render('register.html', RequestContext(request, {'form': form})) obj_user = User.objects if obj_user.filter(username=data['username']).exists() or obj_user.filter(email=data['email']).exists(): messages.error(request, 'user or email already existed') return render('register.html', RequestContext(request, {'form': form})) new_user = obj_user.create_user(username=data['username'], password=data['password'], email=data['email']) new_user.is_active = True new_user.is_staff = True new_user.save() new_profile = UserProfile(user=new_user) try: new_profile.save() return HttpResponseRedirect('/') except: messages.error(request, 'register new user failed!') return render('register.html', RequestContext(request, {'form': form})) return HttpResponseRedirect('/') return render('register.html', RequestContext(request, {'form': form}))
def register(): if session.get("username"): flash("Youur are already logged in", "info") redirect(url_for("manager.index")) form = RegisterForm() if form.validate_on_submit(): username = request.form.get("username") password = request.form.get("password") name = request.form.get("name") email = request.form.get("email") existing_username = User.get(username=username) if existing_username: flash( "Username {} already existst in the database".format(username), "error") return render_template("register.html", form=form) user = User( username=username, name=name, email=email, password=password ) flash('You are now registered. Please login.', 'success') return redirect(url_for("auth.login")) return render_template("register.html", form=form)
def register(): form = RegisterForm() if form.validate(): #if user registers with email, create a username, from their email if form.newusername.data.find('@') != -1: username = form.newusername.data.split('@')[0] email = form.newusername.data else: username = form.newusername.data email = None #checks if username already exists checkuser = User.query.filter_by(username = username).first() if checkuser != None: flash('user name already taken') return redirect(url_for('index')) else: #add new user to database newuser = models.User(username=username, email = email, password=generate_password_hash(form.password.data), fullname = form.fullname.data) dbsess.add(newuser) dbsess.commit() login_user(newuser) #ins = User.insert().values(username=form.username.data, password=generate_password_hash(form.password.data), fullname=form.fullname.data) #db.session.execute(ins) #db.session.commit() return redirect(url_for('index')) return render_template('index.html', registerform = form, loginform = LoginForm())
def register(request): basic = get_basic(request) if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): username = request.POST['username'] password = request.POST['password1'] email = request.POST['email'] user = User.objects.create_user(username, email, password) user.is_active = False user.save() characters = string.ascii_uppercase + string.digits + string.ascii_lowercase confirmation_code = ''.join(random.choice(characters) for x in range(30)) register = Registration(user=user, confirmation_code=confirmation_code) register.save() user = authenticate(username=username, password=password) if user.is_active: login(request, user) return HttpResponseRedirect('/editprofile/') else: send_registration_confirmation(user) return HttpResponseRedirect('/accounts/notverified?id=' + str(user.id)) else: if basic: return HttpResponseRedirect('/') form = RegisterForm() return render(request, 'register.html', {'form': form, 'basic': basic})
def register(request): if request.method == "POST": nextPage = request.POST.get("next", "/") form = RegisterForm(request.POST) if form.is_valid(): try: form.save() except: print "Unable to save form..." return render_to_response("registration/registration.html", {'form': form, 'next': nextPage}, context_instance=RequestContext(request)) user = authenticate(username=request.POST.get("username"), password=request.POST.get("password1")) login(request, user) account = Account() account.user = User.objects.get(pk=user.id) account.created_by = user account.save() return redirect(nextPage) else: print "errors in registration" print form.errors else: form = RegisterForm() nextPage = request.GET.get("next", "/") # return render_to_response("registration/login.html", {}, context_instance=RequestContext(request)) return redirect("ig.api.connectInstagram")
def post(self): data = ImmutableMultiDict(request.json) register_form = RegisterForm(data, csrf_enabled=False) if register_form.validate(): user = register_form.save() return jsonify({"status": "success","data": BaseUserSerializer().dump(user).data}) return register_form.errors
def register(): form = RegisterForm() if request.method == 'POST'and form.validate(): return redirect(url_for('index')) elif form.csrf_token.errors: pass return render_template('register.html', form=form)
def register_user(): if request.method == "POST": form = RegisterForm(request.form) if form.validate(): person = Person( email=form.email.data, age=form.age.data, first_name=form.first_name.data, last_name=form.last_name.data, phone_no=form.phone_no.data, password_hash=form.password.data, twitter_id = form.twitter_id.data, facebook_id = form.facebook_id.data ) db.session.add(person) db.session.commit() flash("Successfully registered as %s" % form.email.data, "success") form1 = LoginForm() return render_template("login.html", form=form1) redirect("login") else: form = RegisterForm() return render_template("register.html", form=form) else: form = RegisterForm() return render_template("register.html", form=form)
def register(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): cleaned = form.cleaned_data ''' send_mail( cd['title'], cd['subject'], cd['format'], cd['host'], cd['date'], ['*****@*****.**'], ) ''' #save a new source from the form's data new_user = form.save() new_user = authenticate(username=request.POST['username'],password=request.POST['password1']) login(request, new_user) return render_to_response('registration/registereduser.html',{'username':cleaned['username'],'next':request.path},RequestContext(request)) else: return render_to_response('registration/register.html', {'form': form,}, RequestContext(request)) else: form = RegisterForm() return render_to_response('registration/register.html', {'form': form,}, RequestContext(request))
def register(): if g.user is not None and g.user.is_authenticated(): flash('You\'re already logged in.') return redirect(url_for('index')) form = RegisterForm() if form.validate_on_submit(): if User.query.filter_by(email = form.email.data).first() != None: flash('This email is already registered. Login instead.') return(redirect(url_for('login'))) if User.query.filter_by(name = form.name.data).first() != None: flash('That name is taken. Try another.') return render_template('register.html', form = form) email = form.email.data name = form.name.data passhash = hashlib.sha224(form.pswd.data + form.email.data).hexdigest() user = User(email = email, name = name, passhash = passhash, role = ROLE_USER) db.session.add(user) db.session.commit() default = Folder(label = 'Default', user_id = user.id) db.session.add(default) db.session.commit() conns = Folder(label = 'Connections', user_id = user.id) db.session.add(conns) db.session.commit() login_user(user) flash("You've successfully registered.") return redirect(url_for('index')) return render_template('register.html', form = form)
def register(request): ''' Creates register form if no form was posted and if form was posted processes the form and creates a user according to the form data. ''' duplicate_username = False password_mismatch = False if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): user_name = form.cleaned_data['username'] email = form.cleaned_data['email'] password = form.cleaned_data['password1'] if not form.cleaned_data['password1'] == form.cleaned_data['password2']: password_mismatch = True if User.objects.filter(username=user_name).exists(): duplicate_username = True if not duplicate_username and not password_mismatch: user = User.objects.create_user(user_name, email, password) user.save() return render(request, 'registered.html') else: form = RegisterForm() return render(request, 'register.html', {'form' : form, 'duplicate_username' : duplicate_username, 'password_mismatch' : password_mismatch})
def register(): register_form = RegisterForm() data = { 'title': 'Register', 'form': register_form, } if register_form.validate_on_submit(): # get data from form username = register_form.username.data password = register_form.password.data confirm_password = register_form.confirmPassword.data email = register_form.email.data # check data if len(username) < 2: flash(u'用户名长度不能小于2!', 'danger') return redirect(url_for('register')) if password != confirm_password: flash(u'两次密码不匹配!', 'danger') return redirect(url_for('register')) if len(password) < 6: flash(u'密码长度不能小于6!', 'danger') return redirect(url_for('register')) if not re.match(r'\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*', email): flash(u'Email地址不规范!', 'danger') return redirect(url_for('register')) # Check Username is already register user = Users.query.filter_by(username=username).first() if user is not None or user: flash(u'用户名已存在!', 'danger') return redirect(url_for('register')) # Insert into database user = Users(id="", username=username, email=email, password=password) db.session.add(user) db.session.commit() user = Users.query.filter_by(username=username).first_or_404() tid = user.id users_info = UsersInfo(id="", user_id=tid, register_time="", last_login_time="", last_login_ip=request.remote_addr, token=random_str(32), is_active=0, qiniu_have_account=0, qiniu_access_key=None, qiniu_secret_key=None, qiniu_bucket_name=None, qiniu_domain=None) db.session.add(users_info) db.session.commit() session['user_id'] = tid # Send mail s = Serializer(app.config['SECRET_KEY'], 3600) token = s.dumps({'user_id': tid}) send_mail(email, ' Please confirm your account', 'mail/confirm', username=username, token=token) # return result flash(u'注册成功!请到邮箱查看验证邮件,验证通过后方可登录。', 'success') return redirect(url_for('register')) return render_template("register.html", data=data)
def register(): form = RegisterForm() if form.validate_on_submit(): return redirect(url_for('index')) return render_template('form.html', title = 'Sign Up', form = form)
def register(): if g.user is not None and g.user.is_authenticated(): return redirect(url_for('intro')) form = RegisterForm() error = None if form.validate_on_submit(): firstname = form.firstname.data lastname = form.lastname.data email = form.email.data.lower() password = form.password.data confirm_password = form.confirm_password.data activate = False pic = ''; user = User.query.filter_by(email=email).first() if '@' not in email or '.' not in email: flash('Invalid email. Please try again.') elif User.query.filter_by(email=email).first() is not None: flash('Email is already registered.') elif password != confirm_password: flash('Please check confirm password') else: user = User(firstname=firstname, lastname=lastname, email=email, password=password, pic=pic, activate=activate) db.session.add(user); db.session.commit() service.send_activate(user) return render_template('welcome.html') return render_template('register.html', title='Register', form=form)
def register(): if _user_is_authenticated(): return redirect('/') form = RegisterForm() if form.validate_on_submit(): if dbsession.query( exists().where(User.email == form.email.data)).scalar(): warning_markup = Markup( 'User with email %(email) already exists. ' 'Click <a href="%(login_link)">here</a> to login.', email=form.email.data, login_link=url_for('login')) flash(warning_markup, 'warning') return render_template('register.html', form=form) user = User(name=form.name.data, email=form.email.data, password_hash=bcrypt.encrypt(form.password.data)) dbsession.add(user) dbsession.commit() login_user(user, remember=True) return redirect('/') else: write_errors_to_flash(form) return render_template('register.html', form=form)
def register(): ''' Handle registering Use get requests to handle registering page Use post requests to handle creation of accounts ''' form = RegisterForm() #if they haven't filled out the form, send them the form with a reminder if not form.validate_on_submit() and request.method == 'POST': return render_template('register.html', form=form, message='Please' ' enter username and password.') elif not form.validate_on_submit(): return render_template('register.html', form=form, message=None) #don't let the user create a duplicate username else: attempted_name = form.username.data if User.query.filter(User.username == attempted_name).first(): return render_template('register.html', form=form, message='Username already taken.') else: user = db_utilities.create_user(form.username.data, form.password.data) login_user(user) return redirect(url_for('home'))
def register(): '''注册页面''' form = RegisterForm() if request.method == 'GET': return render_template('register.html', form = form) else: user = User(userid = form.userid.data, nickname = form.nickname.data, password = form.password.data) if not form.validate_userid(): error = USERID_ERROR elif not form.validate_nickname(): error = NICKNAME_ERROR elif not form.validate_password(): error = PASSWORD_ERROR elif not form.validate_equal(): error = EQUAL_ERROR elif User.query.filter_by(userid = user.userid).first() is not None: error = EXIST_ERROR else: error = None if error: flash(error) return render_template('register.html', form = form) else: db.session.add(user) db.session.commit() login_user(user, remember = True) return redirect('/')
def register(): form = RegisterForm() if request.method == 'POST' and form.validate(): import datetime birthday = is_valid_age(datetime.datetime.strptime(request.form['birthDay'] + "-" + request.form['birthMonth'] + "-" + request.form['birthYear'], '%d-%m-%Y')) user_saved = User.query.filter_by(email=request.form['mail']).first() if user_saved is None: new_user = User( prefix=request.form['prefix'], name=is_valid_string(request.form['name']), middleName=is_valid_string(request.form['middleName']), lastName=is_valid_string(request.form['lastName']), gender=request.form['gender'], birthday=birthday, nationality=request.form['nationality'], codeArea=is_valid_number(request.form['codeArea']), telephone=is_valid_number(request.form['telephone']), email=is_email(request.form['mail']) ) if new_user.prefix == "-" or new_user.gender == "-" or new_user.nationality == "-": raise Exception(u"Por favor, selecciona una opción válida.".encode('utf-8')) db.session.add(new_user) db.session.commit() return render_template('registered.html') else: flash(u'The user is already registered') return render_template('register.html', form=form) else: return render_template('register.html', form=form)
def register(request, template_name="registration/register.html"): if request.method == 'POST': postdata = request.POST.copy() form = RegisterForm(postdata) if form.is_valid(): form.save() un = postdata.get('username', '') pw = postdata.get('password1', '') from django.contrib.auth import login, authenticate new_user = authenticate(username=un, password=pw) if new_user and new_user.is_active: login(request, new_user) url = urlresolvers.reverse('catalog_home') return HttpResponseRedirect(url) else: form = RegisterForm() page_title = u'Регистрация пользователя' return render_to_response(template_name, locals(), context_instance=RequestContext(request)) # from checkout.models import Order, OrderItem # from django.contrib.auth.decorators import login_required # @login_required # def my_account(request, template_name="registration/my_account.html"): # page_title = 'My Account' # orders = Order.objects.filter(user=request.user) # name = request.user.username # return render_to_response(template_name, locals(),context_instance=RequestContext(request))
def auth_register(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] password = form.cleaned_data['password'] user = User.objects.create_user( username=username, first_name=first_name, last_name=last_name, email=email, password=password ) user.save() if user is not None: if user.is_active: #login(request, user) return HttpResponse("Register completed.") # Redirect to a success page. else: return HttpResponse("Disabled account!") # Return a 'disabled account' error message else: return HttpResponse("Invalid Input.") # Return an 'invalid login' error message. form = RegisterForm() return render(request, 'users/auth_register/index.html', { 'form': form })
def sign_up(): form = RegisterForm() if form.validate_on_submit(): # new catalog for user catalog_name = str(form.data['login'] + "_main") new_dir = dbTables.Catalog(catalog_name) db_connection.session.add(new_dir) db_connection.session.commit() # new filespace for user fs_name = str(form.data['login'] + "_fs") new_fs = dbTables.FileSpace(fs_name, new_dir) db_connection.session.add(new_fs) db_connection.session.commit() fs = db_connection.session.execute( sqlalchemy.select([dbTables.FileSpace]) .where(dbTables.FileSpace.storage_name == fs_name)) fs = fs.fetchone() time_is = datetime.datetime.strptime(strftime("%d-%m-%Y", gmtime()), "%d-%m-%Y").date() time_is = time_is + datetime.timedelta(days=365) date_max = time_is.strftime("%Y-%m-%d") id_new = db_connection.session.execute( sqlalchemy.func.count(dbTables.Users.id) ).fetchone()[0] + 1 password_hash = str(sha256(form.data['password'] + str(id_new)).hexdigest()) # create new user new_user = dbTables.Users(form.data['login'], form.data['fullname'], password_hash, form.data['email'], date_max, 1, 2, fs.id) db_connection.session.add(new_user) db_connection.session.commit() return redirect(url_for('success')) return render_template('sign-up.html', title=u"Регистрация", form=form)
def user_register(): """ Register user: show form or handle form submission. """ form = RegisterForm() if form.validate_on_submit(): data = {k: v for k, v in form.data.items() if k != "csrf_token"} new_user = User.register(**data) db.session.add(new_user) db.session.commit() session["username"] = new_user.username flash(f"{new_user.username} added.") # on successful login, redirect to users page return redirect(f"/users/{new_user.username}") return render_template("register.html", form=form)
def post(self, request): form = RegisterForm(request.POST) if form.is_valid(): data = form.cleaned_data username = data['username'] # chinese_name = data['chinese_name'] # group_name = data['group_name'] password = data['password'] password2 = data['password'] if not User.objects.all().filter(username=username): user = User.objects.create_user(username, '', password) user.save() # login_validate(request, username, password) return my_response(code=0, msg="注册成功", content="") else: return my_response(code=1, msg="用户已存在", content="") return my_response(code=1, msg="用户已存在", content="")
def register(): form = RegisterForm() if form.validate_on_submit(): try: print(form.psw.data) hash = generate_password_hash(form.psw.data) u = Users(name=form.name.data, email=form.email.data, psw=hash) print(u) db.session.add(u) db.session.commit() flash("Вы успешно зарегистрированы", "success") except: db.session.rollback() print("Ошибка добавления в БД") return redirect(url_for('profile')) return render_template("register.html", menu=mainmenu, title="Регистрация", form=form)
def register(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): new_user = form.save() messages.success( request, _("Please check your email to verify your account before logging in." )) return HttpResponseRedirect(reverse('accounts_login')) else: return render_to_response('accounts/register.html', RequestContext(request, {'form': form})) #this is an HTTP GET return render_to_response( 'accounts/register.html', RequestContext(request, {'form': RegisterForm()}))
def register(): form = RegisterForm() if form.validate_on_submit(): # здесь должна быть проверка корректности введенных данных try: hash = generate_password_hash(form.password.data) u = User(username=form.username.data, email=form.email.data, password_hash=hash) #u.set_password(hash) db.session.add(u) db.session.commit() return redirect(url_for('index')) except: db.session.rollback() print("Ошибка добавления в БД") flash("Указана почта, которая уже зарегистрирована", 'error') return redirect(url_for('register')) return redirect(url_for('login')) return render_template('register.html', form=form)
def register(): error = None form = RegisterForm() if form.validate_on_submit(): user = User( name=form.username.data, email=form.email.data, password=form.password.data ) user.filename = "profile_pic.jpg" db.session.add(user) db.session.commit() login_user(user) flash("Congrats on your new account!", "success") return redirect(url_for("blog")) return render_template( "register.html", form=form, error=error)
def register(): form = RegisterForm() if form.validate_on_submit(): # if request.method == 'POST': # userid = request.form.get('userid') # username = request.form.get('username') # password = request.form.get('password') # re_password = request.form.get('re-password') # if (userid and username and password and re_password) and password == re_password: user = User() user.userid = form.data.get('userid') user.username = form.data.get('username') user.password = form.data.get('password') #추가하기 db.session.add(user) db.session.commit() print('success') return redirect('/') return render_template('register.html', form=form)
def register(): """If user is logged in then go to homepage, if not then register""" form = RegisterForm() if form.validate_on_submit(): new_user = { 'username': form.username.data, 'email': form.email.data, 'first_name': form.first_name.data, 'last_name': form.last_name.data } password = form.password.data user = User.register(new_user, password) session['username'] = user.username return redirect(f"/users/{user.username}") else: return render_template("/register.html", form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): email = form.email.data if User.query.filter_by(email=email).first(): flash('Email already exists please log in.') return redirect(url_for('login')) else: password = form.password.data name = form.name.data encrypted_pw = generate_password_hash(password=password, method='pbkdf2:sha256', salt_length=8) new_user = User(email=email, password=encrypted_pw, name=name) db.session.add(new_user) db.session.commit() login_user(new_user) return redirect(url_for('get_all_posts')) return render_template("register.html", form=form)
def multi_form(): signin_form = SigninForm() register_form = RegisterForm() # 提交登录表单并且进行验证 if signin_form.submit1.data and signin_form.validate(): username = signin_form.username.data flash('%s, you just submit the Signin Form.' % username) return redirect(url_for('index')) # 提交注册表单并且进行验证 if register_form.submit2.data and register_form.validate(): username = register_form.username.data flash('%s, you just submit the Register Form.' % username) return redirect(url_for('index')) return render_template('2form.html', signin_form=signin_form, register_form=register_form)
def register(): form = RegisterForm() if form.validate_on_submit(): hash_and_salted_password = generate_password_hash( form.password.data, method='pbkdf2:sha256', salt_length=8 ) new_user = User( email=form.email.data, name=form.name.data, password=hash_and_salted_password, ) db.session.add(new_user) db.session.commit() return redirect(url_for("get_all_posts")) return render_template("register.html", form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() email = User.query.filter_by(email=form.email.data).first() if user is None and email is None: user = User(username=form.username.data, password=form.password_one.data, email=form.email.data) db.session.add(user) db.session.commit() token = user.generate_confirmation_token() send_mail(user.email, u'欢迎注册成为本博客用户', 'mail/confirm', user=user, token=token) return redirect(url_for('main.index')) return render_template('auth/register.html', form=form)
def register(): """ Register a user """ # Check if user logged in first if 'username' in session: username = session['username'] return redirect(f'/users/{username}') form = RegisterForm() if form.validate_on_submit(): user_data = generate_user_data(form) new_user = User.register(user_data) db.session.add(new_user) db.session.commit() session['username'] = new_user.username return redirect(f'/users/{new_user.username}') return render_template('register.html', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): if User.query.filter_by(email=form.email.data).first(): flash("You've already signed up with that email, log in instead") return redirect(url_for("login")) strong_password = generate_password_hash(form.password.data, method="pbkdf2:sha256", salt_length=6) new_user = User(email=form.email.data, name=form.name.data, password=strong_password) db.session.add(new_user) db.session.commit() login_user(new_user) return redirect(url_for("get_all_posts")) return render_template("register.html", form=form, current_user=current_user)
def register(request): redirect_url = reverse("account.views.home") if request.user.is_authenticated(): return redirect(redirect_url) if request.method == "POST": form = RegisterForm(data=request.POST) if form.is_valid(): username = form.cleaned_data["username"] password = form.cleaned_data["password1"] try: django_user = form.save() if REGISTER_AUTO_LOGIN: django_user = authenticate(username=username, password=password) djangologin(request, django_user) return redirect(redirect_url) except Exception, e: logging.error("failed to register: %s" % e) DjangoUser.objects.filter(username=username).delete()
def register(): form = RegisterForm() if form.validate_on_submit(): # check first if user already exists user = find_user(form.username.data) if not user: salt = bcrypt.gensalt() password = bcrypt.hashpw(form.password.data.encode(), salt) with open('data/users.csv', 'a') as f: writer = csv.writer(f) writer.writerow([ form.username.data, form.email.data, form.phone.data, password.decode() ]) flash('Registered successfully.') return redirect('/login') else: flash('This username already exists, choose another one') return render_template('register.html', form=form)
def index(theme): if 'username' in session: return redirect('/home') page_config = Config.format( Config.pages["index"], {"username": session.get("username", "Not logged in")}) return render_template('index.jinja', page=page_config, form=RegisterForm(), theme=theme)
def register_user(): """handle register user on post or render register user form""" form = RegisterForm() 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 taken_username = User.query.filter_by(username=username).first() taken_email = User.query.filter_by(email=email).first() if not taken_username and not taken_email: # check if username is available # create user instance user = User.register(username, password, email, first_name, last_name) db.session.add(user) db.session.commit() flash("Registration successful!") user = User.authenticate( username, password ) # don't need to call this method, just add them to the session if user: session[ "username"] = user.username #just check for key of username in session. return redirect( f"/users/{username}" ) # could put this at the very top, less nested if/else else: flash("Authentication failed") # won't need this else clause return redirect("/register") else: flash("Username/email Taken") # move this up to 46 return render_template("register.html", form=form) else: return render_template('register.html', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): #如果验证成功 data = form.data # 保存数据 user = User( account=data["account"], # 对于pwd进行加密 pwd=generate_password_hash(data["pwd"]), add_time=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), ) db.session.add(user) db.session.commit() # 定义一个会话的闪现 flash("注册成功, 请登录!", "ok") return redirect("/login/") else: flash("输入正确信息注册!", "err") return render_template("register.html", title="注册", form=form)
def register(): form = RegisterForm() if request.method == 'POST': if form.validate_on_submit(): # Recieving data password = form.password.data email = form.email.data # Registering user user = User(email=email) user.password = password db.session.add(user) db.session.commit() # Authorizing session["email"] = email session["is_auth"] = True return redirect('/account/') return render_template('register.html', form=form)
def register(): form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): cur = mysql.connection.cursor() query = "INSERT INTO users(name, email, username, password) VALUES(%s, %s, %s, %s)" params = (form.name.data, form.email.data, form.username.data, sha256_crypt.encrypt(str(form.password.data))) cur.execute(query, params) mysql.connection.autocommit(on=True) cur.close() session['logged_in'] = True session['username'] = form.username.data session['name'] = form.name.data flash('Вы успешно зарегистрированы!', 'success') return redirect(url_for('index')) return render_template('register.html', form=form)
def register(): error = None form = RegisterForm(request.form, csrf_enabled=False) if form.validate_on_submit(): new_user = User( form.name.data, form.email.data, form.password.data, ) try: db.session.add(new_user) db.session.commit() flash('Thanks for registering. Please Login.') return redirect(url_for('.login')) except IntegrityError: error = "Oh nopes! That username and/or email already exists. Try Again!" else: flash_errors(form) return render_template('/users/register.html', form=form, error=error)
def register(): error = None form = RegisterForm(request.form) if request.method == 'POST': if form.validate_on_submit(): new_user = User(form.name.data, form.email.data, bcrypt.generate_password_hash(form.password.data)) try: db.session.add(new_user) db.session.commit() flash('Thank you for registering. You may log in.') return redirect(url_for('login')) except IntegrityError: error = 'This username or email already exist. Please try another one.' return render_template('register.html', form=form, error=error) else: return render_template('register.html', form=form, error=error) if request.method == 'GET': return render_template('register.html', form=form)
def register(): register_form = RegisterForm() if register_form.validate_on_submit(): if User.query.filter_by(email=register_form.email.data).first(): flash("You've already signed up with that email, log in instead.") return redirect(url_for('login')) hashed_password = generate_password_hash(register_form.password.data, method='pbkdf2:sha256', salt_length=8) new_user = User(email=register_form.email.data, password=hashed_password, name=register_form.name.data) db.session.add(new_user) db.session.commit() login_user(new_user) return redirect(url_for('get_all_posts')) return render_template("register.html", form=register_form, logged_in=current_user.is_authenticated)
def register(): error = None form = RegisterForm(request.form) if request.method == 'POST': if form.validate_on_submit(): new_user = User( form.name.data, form.email.data, form.password.data, ) try: db.session.add(new_user) db.session.commit() flash('Thanks for registering. Please login.') return redirect(url_for('login')) except IntegrityError: error = 'That username and/or email already exist.' return render_template('register.html', form=form, error=error) return render_template('register.html', form=form, error=error)
def login_register(): login_form = LoginForm() register_form = RegisterForm() u = g.user if u.is_authenticated: return redirect(url_for('general.index')) else: return render_template('general/login_register.html', login_form=login_form, register_form=register_form)
def register(): form = RegisterForm() # if request.method=='Post': # print('post') # if form.validate_on_submit(): # fcuser = Fcuser() # fcuser.userid = form.data.get('userid') # fcuser.username = form.data.get('username') # fcuser.password = form.data.get('password') # fcuser.repassword = form.data.get('repassword') # # print(fcuser.username) # # db.session.add(fcuser) # db.session.commit() # # return redirect('/') # else: # print('retry') # elif request.method == 'GET': # print('get') # else: # print('tlqk') if request.method=='GET': print('get') else: if form.validate_on_submit(): fcuser = Fcuser() fcuser.userid = form.data.get('userid') fcuser.username = form.data.get('username') fcuser.password = form.data.get('password') fcuser.repassword = form.data.get('repassword') print(fcuser.username) db.session.add(fcuser) db.session.commit() return redirect('/') else: print('retry') return render_template('register.html', form=form)
def register_page(): from forms import RegisterForm form = RegisterForm() if form.validate_on_submit(): from models import User hashed_password = bcrypt.generate_password_hash( form.password1.data).decode('utf-8') user_to_create = User(name=form.username.data, email=form.email_address.data, password=hashed_password) db.session.add(user_to_create) db.session.commit() flash("You have successfully created a new account ") return redirect(url_for('market_page')) if form.errors != {}: for err_msg in form.errors.values(): flash(f'There was an error with creating a user: {err_msg}', category='danger') return render_template('register.html', form=form)
def register(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): try: User.objects.get(username=form.data.get('username')) messages.error(request, "That username is already taken!") except User.DoesNotExist: User.objects.create_user( form.data.get('username'), email=form.data.get('email'), password=form.data.get('password') ) messages.success(request, "Thanks for registering!") return HttpResponseRedirect('/login/') else: form = RegisterForm() return render(request, 'registration/register.html', {'form': form})
def register(): form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): name = form.name.data email = form.email.data username = form.username.data password = sha256_crypt.encrypt(str(form.password.data)) #create cursor cur = mysql.connection.cursor() cur.execute( "INSERT INTO users(name, email, username, password) VALUES(%s, %s, %s, %s)", (name, email, username, password)) mysql.connection.commit() cur.close() flash('You are now registerd and can log in', 'success') return redirect(url_for('login')) return render_template('register.html', form=form)