def register(request): reg_form = RegForm() if request.method == 'POST': reg_form = RegForm(request.POST) reg_new(request) if request.user.is_authenticated: return HttpResponseRedirect('/home/') else: elem = { 'title': 'Registrering', 'reg_form': reg_form, } return render_to_response("register.html", elem, context_instance=RequestContext(request))
def reg(): """ 注册 """ # return "Hello, World!\nReg!" form = RegForm() if request.method == 'POST': if form.validate_on_submit(): # 添加用户信息 from user import add_user from datetime import datetime current_time = datetime.utcnow() user_data = { 'email': form.email.data, 'create_time': current_time, 'update_time': current_time, 'last_ip': request.headers.get('X-Forwarded-For', request.remote_addr) } user_id = add_user(user_data) # 添加授权信息 from user_auth import add_user_auth user_auth_data = { 'user_id': user_id, 'auth_type': 'email', 'auth_key': form.email.data, 'auth_secret': form.password.data } user_auth_id = add_user_auth(user_auth_data) if user_auth_id: flash(u'%s, Thanks for registering' % form.email.data, 'success') # todo 发送邮箱校验邮件 email_validate_content = { 'mail_from': 'System Support<*****@*****.**>', 'mail_to': form.email.data, 'mail_subject': 'verify reg email', 'mail_html': 'verify reg email address in mailbox' } send_email_result = send_cloud_client.mail_send( **email_validate_content) # 调试邮件发送结果 if send_email_result.get('result') is False: flash(send_email_result.get('message'), 'warning') else: flash(send_email_result.get('message'), 'success') # https://www.***.com/email/signup/uuid else: flash(u'%s, Sorry, register error' % form.email.data, 'warning') return redirect(url_for('login')) # 闪现消息 success info warning danger flash(form.errors, 'warning') # 调试打开 return render_template('reg.html', title='reg', form=form)
def profile(): #check if currently logged in user has a profile try: profile = UserProfile.query.filter_by(user_id=current_user.id) except: flash("Cannot connect to the database , contact support", "danger") return redirect(url_for('profile')) if profile.count() > 0: #means profile is already existing flash("You have an existing profile saved profile on file", "info") return redirect(url_for('index')) form = RegForm(request.form) if form.validate_on_submit(): first_name = form.first_name.data middle_name = form.middle_name.data last_name = form.last_name.data npi = form.npi.data doctor = form.doctor.data radiologist = form.radiologist.data training = form.training.data clinical_practice = form.clinical_practice.data clinical_specialty = form.clinical_specialty.data clinical_specialty = ''.join(clinical_specialty) institution_type = form.institution_type.data country = request.form['country'] state = request.form['state'] userProfile = UserProfile( first_name=first_name, middle_name=middle_name, last_name=last_name, npi=npi, doctor=doctor, radiologist=radiologist, training=training, clinical_practice=clinical_practice, clinical_specialty=clinical_specialty, institution_type=institution_type, country=country, state=state, user_id=current_user.id) #save to DB try: db.session.add(userProfile) db.session.commit() flash('User profile saved successfully', 'success') return redirect(url_for('worklist')) except: flash('Failed to save user profile !', 'danger') return redirect(url_for('profile')) return redirect(url_for('worklist')) return render_template('profile.html', form=form)
def sign_up(): if current_user.is_authenticated: return redirect(url_for('index')) form = RegForm() 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(url_for('login')) return render_template('sign_up.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('index')) form = RegForm() 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('Congratulations, you are now a registered user!') return redirect(url_for('login')) return render_template('reg.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegForm() if form.validate_on_submit(): hashedPwd = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashedPwd) db.session.add(user) db.session.commit() flash(f'Account created successfully!', 'success') return redirect(url_for('login')) return render_template('register.html', title = 'Register', form = form)
def signUp(): if current_user.is_authenticated: return redirect(url_for('index')) form = RegForm() 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('signIn')) return render_template('registration.html', title='Регистрация', form=form)
def signup(): form = RegForm() if form.validate_on_submit(): hashed_pw = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, password=hashed_pw, standard=form.standard.data, section=form.section.data) db.session.add(user) db.session.commit() return redirect(url_for('login')) app.logger.debug(form.errors) return render_template("signup.html", form=form)
def reg(): if g.user is not None and g.user.is_authenticated: return redirect(url_for('index')) form = RegForm() if form.validate_on_submit(): respemail = form.email.data respepassword = form.password.data nickname = "" if nickname is None or nickname == "": nickname = respemail.split('@')[0] nickname = User.make_valid_nickname(nickname) nickname = User.make_unique_nickname(nickname) user = User(nickname=nickname, email=respemail, password=respepassword) db.session.add(user) db.session.commit() newuser = User.query.filter_by(email=respemail).first_or_404() db.session.add(newuser.follow(newuser)) # 关注自己 db.session.commit() # 发送邮件 subject = sting_utf8("确认你的邮箱") token = ts.dumps(newuser.email, salt='email-confirm-key') confirm_url = url_for( 'member.confirm_email', token=token, _external=True) txt = render_template( 'member/email_confirm.txt', confirm_url=confirm_url) html = render_template( 'member/email_confirm.html', confirm_url=confirm_url) #send_email(subject, '', [newuser.email], txt, html) remember_me = False if 'remember_me' in session: remember_me = session['remember_me'] session.pop('remember_me', None) login_user(user, remember=remember_me) return redirect(request.args.get('next') or url_for('index')) return render_template('member/reg.html', title = sting_utf8('注册'), form = form)
def signuppage(): if current_user.is_authenticated: flash("You are already logged in.", "warning") return redirect(url_for("homepage")) form = RegForm(request.form) if request.method == "POST" and form.validate(): hashed = pwd.generate_password_hash(form.password.data).decode('utf-8') element = User(uname=form.uname.data, email=form.email.data, password=hashed) db.session.add(element) db.session.commit() flash("Account created for %s!" % (form.uname.data), "success") return redirect(url_for("loginpage")) return render_template("signup.html", form=form)
def register(): form = RegForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data, password_hash=form.password.data) db.session.add(user) db.session.commit() # mail_message('Welcome to Pizza App. We value you', 'email/welcome', user.email, user = user) return redirect(url_for('admin')) title = 'Pizza Register' return render_template('register.html', title=title, form=form)
def register(): form = RegForm() if request.method == 'POST': if form.validate_on_submit(): user = User.objects(email=form.email.data).first() if not user: new_user = User.register(email=form.email.data, password=form.password.data, username=form.username.data) os.makedirs( f'{app.config["IMAGE_UPLOADS"]}/{form.username.data}/avatar' ) os.makedirs( f'{app.config["IMAGE_UPLOADS"]}/{form.username.data}/collections' ) login_user(new_user) return redirect('/') return render_template('register.html', form=form)
def register(): if current_user.is_authenticated: redirect(url_for('home')) form = RegForm() if form.validate_on_submit(): hashpw = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashpw, ) db.session.add(user) db.session.commit() return redirect(url_for('home')) return render_template('register.html', form=form, title='Register', current_user=current_user, )
def signup(): """ Регистрация пользователя. """ if current_user.is_authenticated: return redirect(url_for('index')) form = RegForm() if form.validate_on_submit(): user = User.manager.create(nick=form.nickname.data, passd=form.password1.data) login_user(user, remember=True) return redirect(url_for('index')) return render_template('auth/registration.html', title='Регистрация', form_reg=form)
def register(): if current_user.is_authenticated: return redirect(url_for('dashboard')) form = RegForm() if form.validate_on_submit(): doc_ref = db.collection('users').document(form.username.data) if doc_ref.get().to_dict() is not None: flash('Username already taken') return redirect(url_for('register')) doc_ref.set({'name': '', 'pass_hash': '', 'cars': [], 'rentals': []}) user = User(form.username.data) user.set_name(form.name.data) user.set_password(form.password.data) flash( f'Created account with username {form.username.data}. You may now sign in.' ) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') return redirect(next_page) return render_template('register.html', title='Sign up', form=form)
def post_user(): """ User is created and authorized """ form = RegForm() if request.content_type != 'application/x-www-form-urlencoded': error_msg = 'Invalid content type' response = make_response({"error": error_msg}, 400) return response if not form.validate_on_submit(): error_msg = 'Invalid form data' response = make_response({"error": error_msg}, 400) return response data = { "name": form.name.data, "password": form.password.data, "email": form.email.data } if User.query.filter(User.name == data["name"]).first() is None: user = User(**data) user.token = get_token() user.hash_password() db.session.add(user) db.session.commit() response = make_response({"status": "ok"}, 201) response.headers["Location"] = f"http://{request.host}/api/chats" response.set_cookie('user_id', str(user.id)) response.set_cookie('access_token', user.token) return response error_msg = 'User already exist' response = make_response(error_msg, 400) return response
def register(): """ /* Inserting data in DB if not exists /* if exists - throwing error (not with flash) :return: """ error = None form = RegForm() if form.validate_on_submit(): if not checkForReg(form.username.data): with session_scope() as session: session.add( Auth(form.username.data, form.password.data, datetime.datetime.now().strftime("%H:%M:%S"), 0)) flash("Successfully registered") else: error = "User already exists" print(error) return render_template("registration.html", title="Register", form=form, error=error)
def register(): form = RegForm() if form.validate_on_submit(): return redirect(url_for('index')) return render_template('register.html', form=form)
def register(): # get forms from group mate repository form=RegForm() #form =RegForm(CombinedMultiDict((request.files, request.form))) filefolder = UPLOAD_FOLDER if request.method == 'POST': pwordcheck = db.session.query(User).all() pexists = False for user in pwordcheck: if check_password_hash(user.password, form.password.data): pexists = True if form.validate_on_submit() and User.query.filter_by(username=form.username.data).first() is None and pexists==False and User.query.filter_by(email=form.email.data).first() is None: #try to figure how to hash password here so that you can check it as well # Get the username and password values from the form. uname = form.username.data fname = form.firstname.data lname = form.lastname.data password = form.password.data location = form.location.data now = datetime.datetime.now() currentDate = now.strftime("%B-%d-%Y") #currentDate = now.strftime("%d-%B-%Y %H:%M:%S") email = form.email.data biography = form.biography.data #file= form.photo.data file = request.files.get('file') file=form.photo.data if file: print("FILE EXISTS"); print(form.photo.data.filename) filename = secure_filename(form.photo.data.filename) form.photo.data.save(os.path.join(filefolder, filename)) #file = request.files['inputFile'] """UNameTest = User.query.filter_by(username=uname).first() if UNameTest is not None:""" user= User( uname,fname, lname,password, location, email,biography,file.filename,currentDate) db.session.add(user) db.session.commit() return jsonify(access = 'true',UINFO = uname) #flash('User Added successfully.', 'success') else: errors = form_errors(form) status = "wrong" if pexists ==True: errors.append("Password already exists!") if User.query.filter_by(username=form.username.data).first() is not None: uNameError = "User name already exists" errors.append(uNameError) if User.query.filter_by(email=form.email.data).first() is not None: MailError = "Email Address already exists" errors.append(MailError) """if User.query.filter_by(password=).first() is not None: MailError = "Passwor already in use" errors.append(MailError)""" return jsonify(error=errors,access = "fail")