def register(): register_form = Register() if register_form.validate_on_submit(): username = register_form.username.data password = register_form.password.data email = register_form.email.data first = register_form.first_name.data last = register_form.last_name.data user = User.register(username, password, email, first, last) userx = User.query.filter_by(username=username).first() if userx: flash(f"username {user.username} already taken") return redirect('/register') else: try: db.session.add(user) db.session.commit() session["username"] = user.username flash(f"Welcome {username}!") return redirect("/") except IntegrityError: db.session.rollback() flash('Username or Email already taken') return redirect('/register') else: return render_template("register.html", register_form=register_form)
def register(request):#注册页面的效验和存库 res = {"type": "error", "data": ""} if request.method == "POST": reg = Register(request.POST,request.FILES) #对数据进行校验 #reg = Register({"username":"******","password“:”123456“}) if reg.is_valid(): cleand_data = reg.cleaned_data #验证通过的字典形式的数据 username = cleand_data["username"] password = cleand_data["password"] email = cleand_data["email"] phone = cleand_data["phone"] photo = cleand_data["photo"] user = CMDBUser() user.username = username user.password = getmd5(password) #加密密码 user.email = email user.phone = phone #保存图片 name = "static/image/"+photo.name img = Image.open(photo) img.save(name) #数据库当中存储图片的路径 user.photo = "image/"+photo.name user.save() res["type"] = "success" res["data"] = "success" else: res["data"] = reg.errors else: res["data"] = "request error" return JsonResponse(res)
def signup(): form = Register() if request.method == 'POST': if form.validate_on_submit(): with open('app/static/accounts.json', 'r') as accounts_file: accounts = load(accounts_file) for account in accounts: if form.username.data == account['username']: flash("This username was taken. Please try again", category='username_error') return redirect(url_for("signup")) new_account = { 'firstname': form.firstname.data, 'lastname': form.lastname.data, 'emailaddress': form.email.data, 'username': form.username.data, 'password': form.password.data, 'followers': [], 'following': [] } accounts.append(new_account) with open('app/static/accounts.json', 'w') as all_accounts: dump(accounts, all_accounts, indent=4, sort_keys=True) return redirect(url_for('login')) return render_template('signup.html', form=form)
def user_list(request): if request.method == "POST": data = request.POST img = request.FILES register = Register(data,img) if register.is_valid(): #检测提交数据是否正常 validData = register.cleaned_data username = validData.get("username") password = validData.get("password") phone = validData.get("phone") email = validData.get("email") photo = img.get("photo") name = "static/img"+photo.name img = Image.open(photo) img.save(name) user = User() user.username = username user.password = getmd5(password) user.phone = phone user.email = email user.photo = "img/"+photo.name user.save() else: register = Register() return render(request,"userList.html",locals())
def register(): """ 用户注册的处理。 """ REGISTER_HTML_PATH = "auth/register.html" form = Register() if form.validate_on_submit(): email = form.email.data nickname = form.nickname.data passwd = form.passwd.data confirm = form.confirm.data new_user = User(email=email, nickname=nickname, passwd=passwd) try: db.session.add(new_user) db.session.commit() except Exception as e: db.session.rollback() flash("Database Error!") return render_template(REGISTER_HTML_PATH, form=form) token = new_user.generate_confirmation_token() send_async_email(new_user.email, "Confirm Your Account", "auth/email/confirm",\ user=new_user, token=token) # to, subject, template, **kwargs flash('A confirmation email has been sent to you by email.') session["nickname"] = nickname return redirect(url_for("main.index")) return render_template(REGISTER_HTML_PATH, form=form)
def user_save(request): ''' 注册用户 :param request: :return: ''' result = {'status': 'error', 'data': ''} if request.method == 'POST': obj = Register(request.POST) if obj.is_valid(): print '表单校验成功:', obj.cleaned_data username = obj.cleaned_data['username'] password = getmd5(obj.cleaned_data['password']) # 入库 try: CMDBUser.objects.create(username=username, password=password) except Exception as e: print e result['data'] = '注册失败' else: result['status'] = 'success' result['data'] = '用户注册成功' else: print '表单校验失败:', obj.errors result['data'] = '注册失败' return JsonResponse(result)
def register(): form = Register() if form.validate_on_submit(): name = form.name.data pwd = form.pwd.data if_register(name, pwd) flash('注册成功') return redirect(url_for('user_console_noreply', user_id=name)) return render_template('register.html', form=form)
def register(request): """my register""" if request.method == "POST": form = Register(request.POST) if form.is_valid(): user = form.save() success = "<html>sign_up_success</html>" return HttpResponse(success) else: form = Register() return render_to_response("sign_up.html", {"form": form}, context_instance=RequestContext(request))
def register(request): """my register""" if request.method == 'POST': form = Register(request.POST) if form.is_valid(): user = form.save() success="<html><h1 align=center>Sign_up_success</h1></html>" return HttpResponse(success) else: form = Register() return render_to_response('sign_up.html', {'form':form}, context_instance=RequestContext(request))
def register(request): if request.method == 'POST': form = Register(request.POST) if form.is_valid(): user = form.save(commit=False) user.set_password(request.POST['password']) user.save() new_user = authenticate(username=request.POST['username'], password=request.POST['password']) auth_login(request, new_user) return render(request, 'forms/hello.html') else: form = Register() return render(request, "forms/registeration.html", {'form':form})
def add_user(): """ This function handles the event of register form submission""" registrationForm = Register(request.form) loginForm = Login(request.form) if request.method == "POST" and registrationForm.validate(): message = register_user(registrationForm.data) if message is None: flash('Hello {name}, please login here'.format(name=request.form[ "username"])) return redirect(url_for('startpage',n=0)) else: flash(message, 'error') return render_template('users/register.html', registrationForm=registrationForm, loginForm=loginForm)
def register(request): blogtype = BlogType.objects.all() if request.method == 'POST': form = Register(request.POST) if form.is_valid(): user = form.save(commit=False) user.set_password(request.POST['password']) user.save() new_user = authenticate(username=request.POST['username'], password=request.POST['password']) auth_login(request, new_user) return redirect('/') else: form = Register() return render(request, "register.html", {'form':form, 'blogtype': blogtype})
def add_user(): """ This function handles the event of register form submission""" registrationForm = Register(request.form) loginForm = Login(request.form) if request.method == "POST" and registrationForm.validate(): message = register_user(registrationForm.data) if message is None: flash('Hello {name}, please login here'.format( name=request.form["username"])) return redirect(url_for('startpage', n=0)) else: flash(message, 'error') return render_template('users/register.html', registrationForm=registrationForm, loginForm=loginForm)
def register(): form = Register() if 'email' in session: return redirect(url_for("index")) if request.method == "POST": if form.validate() == False: return render_template("register.html", form=form) else: new_user = User(form.first_name.data, form.last_name.data, form.email.data, form.password.data) db.session.add(new_user) db.session.commit() session['email'] = new_user.email return redirect(url_for("index")) return render_template("register.html", form=form)
def regist(): mongo = PyMongo(app) reg = Register() log = Login() user = '' '''註冊實作''' if True: '''加入Friend''' friends = mongo.db.User_Info.find() temp = [] for f in friends: temp.append(f['username']) friend = { 'username' : reg.data['username'], 'Friends' : temp} mongo.db.Friend.insert_one(friend) '''加入Select''' sel = { 'username' : reg.data['username'], 'fencescale' : 10, 'person' : reg.data['username']} mongo.db.Select_People.insert_one(sel) '''加入User_Info''' new_user = { 'username' : reg.data['username'], 'password' : reg.data['password'] } mongo.db.User_Info.insert_one(new_user) user = User() user.id = reg.data['username'] login_user(user) return redirect(url_for('home'))
def signUp(): form = Register() if request.method == 'POST': if form.validate == True: flash('All fields are required!') return render_template('signup.html', form=form) else: usrnm = request.form['username'] email = request.form['email'] password = request.form['password'] password = generate_password_hash(password) email_exists = ta_email.query.filter_by(email=email).first() if email_exists is None: flash('You are not authorised to signup ):') return render_template('signup.html', form=form, flag=0) else: user = Users(name=usrnm, email=email, password=password) check_usrnm = user.query.filter_by(name=usrnm).first() check_email = user.query.filter_by(email=email).first() if check_usrnm is not None: flash('Username already exists!') return render_template('signup.html', form=form, flag=0) elif check_email is not None: flash('Email already registered!') return render_template('signup.html', form=form, flag=0) else: db.session.add(user) db.session.commit() flash('Registered succesfully!') return render_template('signup.html', form=form, flag=1) elif request.method == 'GET': return render_template('signup.html', form=form)
def user_list(request): ''' 用户注册 ''' register = Register if request.method == 'POST': obj = Register(request.POST, request.FILES) if obj.is_valid(): print '表单校验成功:', obj.cleaned_data user_data = obj.cleaned_data user_data['password'] = getmd5(user_data['password']) print user_data['password'] User.objects.create(**user_data) else: print '校验失败:', obj.errors return render(request, 'userList.html', locals())
def register(request): form = Register(request.POST) form2 = Login() if request.method == 'POST': if form.is_valid(): email = form.cleaned_data['email'] create = User.objects.create(name = form.cleaned_data['name'], alias = form.cleaned_data['alias'], email = form.cleaned_data['email'], password = bcrypt.hashpw(form.cleaned_data['password'].encode('utf8'), bcrypt.gensalt() )) messages.add_message(request, messages.INFO, form.cleaned_data['name'], extra_tags="name") return redirect('/') context = { "form": form, "form2": form2, } return render(request, "belt_reviewer/index.html", context)
def register(request): """ generate user register form """ if request.method == 'POST': form = Register(request.POST) if form.is_valid(): user = form.save() if user: success = "<html>sign_up_success</html>" return HttpResponse(success) else: form = Register() context = {'form':form} return render_to_response("register.html", context, context_instance=RequestContext(request))
def kiosk(): if request.method == 'GET': form = Register() title = "Giant Ball of String" return render_template('base.html', title=title, form=form) if request.method == 'POST': # We are receiving data from the user (phone number) form = Register(request.form) phonenumber = form.phonenumber.data if form.validate(): logger.info( 'Received registration for number {}'.format(phonenumber)) prepare_data(phonenumber) return redirect('/') else: logger.error("Did not receive valid form")
def index(request): form = Register() login = Login() context = { 'form': form, 'form2': login, } return render(request, "belt_reviewer/index.html", context)
def register(): if current_user.is_authenticated: return redirect('/', 302) form = Register() if request.method == 'POST': if form.validate_on_submit(): user = User(name=form.name.data.title(), userID=str(uuid4())[::-1], username=form.username.data.lower(), password=form.password.data, email=form.email.data.lower(), gender=form.gender.data) user.saveUser() login_user(user) return redirect('/', 302) return render_template('register.html', form=form)
def user_save(request): ''' 注册用户 :param request: :return: ''' result = {'status': 'error', 'data': ''} if request.method == 'POST': obj = Register(request.POST) if obj.is_valid(): #print '表单校验成功:',obj.cleaned_data username = obj.cleaned_data['username'] password = getmd5(obj.cleaned_data['password']) groupname = request.POST.get('groupname') try: # 用户入库 u = CMDBUser(username=username, password=password) u.save() uid = u.id except Exception as e: print e result['data'] = '添加用户失败' else: try: # 判断用户提交的组是否存在 g = CMDBGroup.objects.get(name=groupname) gid = g.id except Exception as e: result['data'] = str(e) else: try: # 用户组关系入库 User_group.objects.create(user_id=uid, group_id=gid) except Exception as e: result['data'] = str(e) else: result['status'] = 'success' result['data'] = '添加用户成功' else: print '表单校验失败:', obj.errors result['data'] = '添加用户失败' return JsonResponse(result)
def register(req): if req.method == 'POST': form = Register(req.POST) if form.is_valid(): try: user = User.objects.get(username = req.POST.get('name')) except: user = None if user is not None: form = Register() return rtr('register.html', { 'error': 'User name already exist!', 'form': form }, RequestContext(req, {})) return redirect('/') else: form = Register() return rtr('register.html', { 'form': form }, RequestContext(req, {}))
def register(): register_form = Register() if register_form.validate_on_submit(): first = register_form.firstname.data last = register_form.lastname.data username = register_form.username.data if check_username_exist(username): flash("Username already in use!") return redirect(url_for("register")) password_hash = generate_password_hash( password=register_form.password.data) current_collection.insert({ "firstname": first, "lastname": last, "username": username, "hashed_pw": password_hash }) flash(f"Thank you for registering {first}!") return redirect(url_for("register")) return render_template('register.html', form=register_form)
def register(): if current_user.is_authenticated: return redirect(url_for('/')) form = Register() error = None if form.validate_on_submit(): username = form.username.data password = form.password.data bot_status = "on" if not db.session.query(User).filter( User.username == username).count(): reg = User(username, password, bot_status) db.session.add(reg) db.session.commit() return redirect(url_for('login')) error = 'User with the same username already exists!' return render_template('register.html', title='Register', form=form, error=error)
def register(): if current_user.is_authenticated: return redirect(url_for('chat')) form = Register() error = None if form.validate_on_submit(): email = form.username.data username = form.name.data password = form.password.data mobile = form.mobile.data if not db.session.query(User).filter(User.email == email).count(): reg = User(email, username, password, mobile) db.session.add(reg) db.session.commit() return redirect(url_for('signin')) error = 'User with the same email already exists!' return render_template('register.html', title='Register', form=form, error=error)
def register(): form = Register() 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=username, password=password, email=email, first=first_name, last=last_name) db.session.add(new_user) db.session.commit() session['username'] = new_user.username return redirect('/secret') return render_template("register.html", form=form)
def register(request): res = {"type": "error", "data": ""} if request.method == "POST": #获取值 reg = Register(request.POST, request.FILES) #对数据进行校验 #外部数据方式 # reg = Register({'username':'******','password':'******'}) if reg.is_valid(): cleaned_data = reg.cleaned_data #验证通过典形式的数据 username = cleaned_data['username'] password = cleaned_data['password'] email = cleaned_data['email'] phone = cleaned_data['phone'] photo = cleaned_data['photo'] user = CmdbUser() user.username = username user.password = getmd5(password) #加密密码 user.email = email user.phone = phone user.photo = photo name = 'static/image/' + photo.name img = Image.open(photo) #先打开图片源码 img.save(name) #保存图片 #数据库当中存储图片的路径 user.photo = 'image/' + photo.name user.save() #保存数据库 res["type"] = "success" res["data"] = "success" else: res["data"] = reg.errors else: res["data"] = "request error" return JsonResponse(res)
def register(): """Register new user.""" form = Register() errors = None if form.validate_on_submit(): username = request.form["username"] query = db.execute("SELECT username FROM users WHERE username = ?", (username,)) if not query: password = request.form["password"] db.execute("INSERT INTO users (username, hash) VALUES (?, ?)", (username, generate_password_hash(password))) # Log user in query = db.execute("SELECT user_id FROM users WHERE username = ?", (username,)) session["user_id"] = query[0]["user_id"] flash("Registered!") return redirect(url_for("index")) else: errors = ["Username already taken."] return render_template("register.html", form=form, errors=errors)
def login_post(): loginForm = Login(request.form) registrationForm = Register(request.form) if loginForm.validate(): user = User() username = request.form['username'] password = request.form['password'] uid = user.get_id(username) if uid is not None and user.check_pass(username, password): return log_user_in(username, uid) flash('Invalid username or password', 'error') return render_template('users/login.html', loginForm=loginForm, registrationForm=registrationForm)
def register(): form = Register() 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 user = User.register(username, password, email, first_name, last_name) db.session.add(user) db.session.commit() if user: session["username"] = user.username flash("You made it!") return redirect("/users/" + str(user.username)) else: form.username.errors = ["Invalid input."] else: return render_template("register.html", form=form)
def index(): '''Main page of Insight Treats''' log = Login() reg = Register() con = Contact() if request.cookies.get('userID'): userID = request.cookies.get('userID') username = validate_cookie(userID) if userID == make_cookie_hash(username): return redirect(url_for('student', username=username)) else: return redirect(url_for('logout')) else: return render_template('index.html', log=log, reg=reg, con=con)
def home(): mongo = PyMongo(app) reg = Register() log = Login() user = '' if current_user.is_active: user = current_user.id '''登入實作''' if log.validate_on_submit(): user = User() user.id = log.data['username'] login_user(user) return redirect(url_for('home')) # '''註冊實作''' # if reg.validate_on_submit(): # '''加入Friend''' # friends = mongo.db.User_Info.find() # temp = [] # for f in friends: # temp.append(f['username']) # friend = { 'username' : reg.data['username'], # 'Friends' : temp} # mongo.db.Friend.insert_one(friend) # '''加入Select''' # sel = { 'username' : reg.data['username'], # 'fencescale' : 10, # 'person' : reg.data['username']} # mongo.db.Select_People.insert_one(sel) # '''加入User_Info''' # new_user = { 'username' : reg.data['username'], # 'password' : reg.data['password'], # 'bracelet_number' : reg.data['bracelet_number'], # 'acount_mode' : 'OWNER', # 'organization' : reg.data['organization'] # } # mongo.db.User_Info.insert_one(new_user) # user = User() # user.id = reg.data['username'] # login_user(user) # return redirect(url_for('home')) return render_template('index.html',reg = reg, log = log, user = user)
def register(): form = Register() message = "" if request.method == "POST": if form.password.data != form.confirm_pass.data: message = "The passwords provided did not match!\n" elif User.query.filter_by(username=form.username.data).all(): message = "This username is taken!" else: #Add user to db user = User(name=form.name.data, username=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() message = "Registered successfully!" return render_template('register.html', form=form, message=message)
def register(request): if request.method == 'POST': form = Register(request.POST) if form.is_valid(): user = form.save(commit=False) user.set_password(request.POST['password']) user.save() new_user = authenticate(username=request.POST['username'], password=request.POST['password']) auth_login(request, new_user) return render(request, 'forms/hello.html') else: form = Register() return render(request, "forms/registeration.html", {'form': form})
def login(): log = Login() reg = Register() if request.method == 'POST': uname = request.form['uname'] pwd = request.form['pwd'] if (uname == "" or pwd == ""): flash('Please fill out all the fields!') return redirect(url_for('login')) c.execute("select password from student where username = %s", (bleach.clean(uname), )) result = c.fetchone() if result != None and result[0] == make_pwd_hash(uname, pwd): c.execute("select active from student where username = %s", (bleach.clean(uname), )) result = c.fetchone() if result[0] == 'y': cook = request.form.get('cook') if cook: c.execute("select iam from profile where username = %s", (bleach.clean(uname), )) fetch = c.fetchone() if fetch != None: return "success" else: return "edit" else: flash( 'Activate your account first with the link sent to your mail!' ) return redirect(url_for('login')) else: flash('Incorrect UserName or Password!') return redirect(url_for('login')) elif request.method == 'GET': return render_template('login.html', log=log, reg=reg)