def signup(request): if request.method == 'GET': logger.info("creating new user form") form = UserForm() return render(request, 'signup.html', { 'form': form, }) elif request.method == 'POST': logger.info("saving a new list") form = UserForm(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, email=email, password=password) user.first_name = first_name user.last_name = last_name user.save() emailutil.send_welcome_email(user) user = auth.authenticate(username=username, password=password) auth.login(request, user) return HttpResponseRedirect('/home/') # Redirect after POST else: return render(request, 'signup.html', { 'form': form }) else: logger.info("invalid operation")
def profile(request): if request.session['email']: if request.method=='POST': a=Register.objects.get(email=request.session['email']) try: b=UserEditPro.objects.get(user=a) except: b=UserEditPro(user=a) b.save() b=UserEditPro.objects.get(user=a) form=UserForm(request.POST,instance=b) if form.is_valid(): f=form.save(commit=False) f.user=a f.save() return HttpResponseRedirect('/blog/login/') else: return render(request,'blog/profile.html',{'form':form}) else: a=Register.objects.get(email=request.session['email']) try: b=UserEditPro.objects.get(user=a) except: b = UserEditPro(user=a) b.save() b=UserEditPro.objects.get(user=a) form=UserForm(instance=b) return render(request,'blog/profile.html',{'form':form}) else: return HttpResponseRedirect('blog/login/')
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) if user_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() registered = True firstname = user_form['first_name'].value() lastname = user_form['last_name'].value() subject = 'Report Viewer Registration: {}, {}'.format( lastname, firstname) message = 'User {} {} <{}> has registered and needs to be vetted.'.format( firstname, lastname, user.email) send_mail(subject, message, '*****@*****.**', ['*****@*****.**'], fail_silently=False) else: print user_form.errors else: user_form = UserForm() context = {'user_form': user_form, 'registered': registered} context.update(csrf(request)) return render_to_response('viewer/register.html', context, context_instance=RequestContext(request))
def add_recommender_user(): form = UserForm() if form.validate_on_submit(): recommenderuser = RecommenderUser(username = form.username.data) recommenderuser.put() flash('New user ' +form.username.data+ ' added to list') return redirect(url_for('manage_users'))
def edit_user(request, id): user = get_object_or_404(User, id=id) if request.method == 'POST': form = UserForm(request.POST, instance=user) if form.is_valid(): user = form.save(commit=False) if form.cleaned_data['password']: user.set_password(form.cleaned_data['password']) if form.cleaned_data['groups']: user.groups = form.cleaned_data['groups'] else: user.groups.clear() if form.cleaned_data['user_permissions']: user.user_permissions = form.cleaned_data['user_permissions'] else: user.user_permissions.clear() user.save() return redirect('accounts:administration:users_list') else: form = UserForm(instance=user) return render(request, 'accounts/administration/edit_user.html', { 'form': form })
def index(request): # Process the form data if request.method == "POST": crisisUserForm = CrisisUserForm(request.POST) userForm = UserForm(request.POST) assert crisisUserForm.is_valid() assert userForm.is_valid() if crisisUserForm.is_valid() and userForm.is_valid(): crisisUserForm_data = crisisUserForm.cleaned_data userForm_data = userForm.cleaned_data new_user = User.objects.create_user(**userForm_data) new_user.save() crisis_user = CrisisUser.objects.create(user=new_user, **crisisUserForm_data) crisis_user.save() return HttpResponseRedirect(reverse('bluehack:register', args=(userForm_data['username'],))) return render(request, 'bluehack/index.html', {'error': 'Failed to register'}) # Create a blank form if any other method else: crisisUserForm = CrisisUserForm() userForm = UserForm() return render(request, 'bluehack/index.html', { 'error': '', 'crisisUserForm': crisisUserForm, 'userForm': userForm })
def register(request): if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] print profile.picture print type(profile.picture) profile.save() username = request.POST.get('username') password = request.POST.get('password') user = authenticate(username=username, password=password) login(request, user) return redirect('/blog/') else: print user_form.errors error = user_form.errors.as_data().values()[0][0].messages[0] print type(error) return render(request, 'blog/auth/register.html', {'error': error}) else: return render(request, 'blog/auth/register.html')
def edit_admin(request, pk): admin_form = AdminForm(prefix="adm") user_form = UserForm(prefix="usr") user = get_object_or_404(User, pk=pk) admin = get_object_or_404(Admin, user_id=user.pk) if request.method == 'POST': admin_form = AdminForm(request.POST, prefix="adm", instance=admin) user_form = UserForm(request.POST, prefix="usr", instance=admin.user) if user_form.is_valid() and admin_form.is_valid(): user = user_form.save() admin = admin_form.save(commit=False) admin.user = user admin.pic = request.FILES['adm-pic'] admin.save() #request.user = user request.user.save() return redirect('admin_details', matriculation=admin.matriculation) else: messages.error(request, "Error") return render(request, 'locker_manager/register_admin.html',{'admin_form':admin_form, 'user_form':user_form}) else: admin_form = AdminForm(prefix="adm", instance=admin) user_form = UserForm(prefix="usr", instance=admin.user) return render(request, 'locker_manager/register_admin.html',{'admin_form':admin_form, 'user_form':user_form})
def register(request): context = RequestContext(request) # boolean to determine if registation was succesful registered = False # if HTTP post then process from data if request.method == 'POST': # grab info user_form = UserForm(data = request.POST) #profile_form = UserProfileForm(data = request.POST) if user_form.is_valid(): # save form to dadabase user = user_form.save() user.set_password(user.password) user.save() # sort user profile instance, set as false to avoid integrity problems #profile = profile_form.save(commit = False) #proifle.user = user registered = True return render_to_response('tasks/index.html', {'user', user}, context) else: # if form not complete or wrong print(user_form.errors) else: user_form = UserForm() #profile form doesn't work, cant get django to add ID# #profile_form = UserProfileForm() context_dict = {'user_form': user_form, 'registered': registered} return render_to_response('tasks/index.html', context_dict, context)
def add(): form = UserForm() if request.method == "POST" and form.validate_on_submit(): users.add(g.url_rest, form) flash("User added") return redirect(url_for("users.list")) return render_template("user_add.html", form=form)
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render(request, 'rango/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
def List(request): try: if CheckAccess(request,'23') != 'OK': return render_to_response("mtmc/notaccess/mtmc.html") except: return HttpResponseRedirect('/') if request.method == 'POST': formuser = UserForm(request.POST) if formuser.is_valid(): user = formuser.cleaned_data['user'] request.session['user_id'] = user formsearch = SearchForm(request.POST) if formsearch.is_valid(): search = formsearch.cleaned_data['search'] r = FindKey(search) if len(r) == 1: return HttpResponseRedirect('/mtmcedit/?eq_id=%s' % search) ### --- Сохранное занчение user_id --- try: user_id = request.session['user_id'] except: user_id = '' try: print_ok = request.GET['print'] response = HttpResponse(content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename="list.pdf"' buff = StringIO() result = PrintForm(buff,user_id) response.write(result.getvalue()) buff.close() return response except: pass formmove = MoveForm(None) formsearch = SearchForm(None) formuser = UserForm(None) formuser.fields['user'].initial = user_id data = GetList(user_id) if len(data)!=0 and user_id != 'ALL': print_ok = True else: print_ok = False c = RequestContext(request,{'data':data,'formuser':formuser,'formsearch':formsearch,'formmove':formmove,'print_ok':print_ok}) c.update(csrf(request)) return render_to_response("mtmc/list.html",c)
def newuser(): if cas.username is None: return redirect('login') if Player.query.filter(Player.netid==cas.username).first() is not None: return redirect('/index') form = UserForm() if form.validate_on_submit(): if form.password.data != SECRET_PASS: return render_template('newuser.html',form=form,validnumber=1,validname=1,validpass=0) if not name_check(form.name.data,1): return render_template('newuser.html',form=form,validnumber=1,validname=0,validpass=1) try: num = int(form.number.data) except: return render_template('newuser.html',form=form,validnumber=0,validname=1,validpass=1) if num != 0: if num >= 10000000000: return render_template('newuser.html',form=form,validnumber=0,validname=1,validpass=1) if not number_check(form.number.data,form.name.data): return render_template('newuser.html',form=form,validnumber=0,validname=1,validpass=1) p = Player(netid=cas.username,name=form.name.data,email=form.email.data) db.session.add(p) if num != 0: u = User(number='+1'+form.number.data,name=form.name.data,admin=0,blocked=0,panlist_id=1) db.session.add(u) db.session.commit() return redirect('/index') return render_template('newuser.html',form=form,validnumber=1,validname=1,validpass=1)
def Register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) c_form = UserCreateForm(data=request.POST) if user_form.is_valid() and c_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() c = c_form.save(commit=False) c.user = user c.save() c_form.save_m2m() registered = True else: print user_form.errors, c_form.errors else: user_form = UserForm() c_form = UserCreateForm() return render(request, 'gadgetapp/register.html', {'user_form': user_form, 'c_form': c_form, 'registered': registered}, RequestContext(request))
def profile(request): # We always have the user, but not always the profile. And we need a bit # of a hack around the normal forms code since we have two different # models on a single form. (profile, created) = UserProfile.objects.get_or_create(pk=request.user.pk) if request.method == "POST": # Process this form userform = UserForm(data=request.POST, instance=request.user) profileform = UserProfileForm(data=request.POST, instance=profile) if userform.is_valid() and profileform.is_valid(): userform.save() profileform.save() return HttpResponseRedirect("/account/") else: # Generate form userform = UserForm(instance=request.user) profileform = UserProfileForm(instance=profile) return render_to_response( "account/userprofileform.html", {"userform": userform, "profileform": profileform}, NavContext(request, "account"), )
def register(request): # Like before, get the request's context. context = RequestContext(request) # A boolean value for telling the template whether the registration was successful. # Set to False initially. Code changes value to True when registration succeeds. registered = False # If it's a HTTP POST, we're interested in processing form data. if request.method == 'POST': # Attempt to grab information from the raw form information. # Note that we make use of both UserForm and UserProfileForm. user_form = UserForm(data=request.POST) profile_form = UserProfileForm(request.POST,request.FILES) # p = UserProfileForm(data=request.FILES) # If the two forms are valid... if user_form.is_valid() and profile_form.is_valid():# and p.is_valid(): # Save the user's form data to the database. user = user_form.save() # Now we hash the password with the set_password method. # Once hashed, we can update the user object. user.set_password(user.password) user.save() # Now sort out the UserProfile instance. # Since we need to set the user attribute ourselves, we set commit=False. # This delays saving the model until we're ready to avoid integrity problems. profile = profile_form.save(commit=False) profile.user = user # Did the user provide a profile picture? # If so, we need to get it from the input form and put it in the UserProfile model. if 'picture' in request.FILES: # p.picture = request.FILES['picture'] # p.save() profile.picture = request.FILES['picture'] # Now we save the UserProfile model instance. profile.save() # Update our variable to tell the template registration was successful. registered = True # Invalid form or forms - mistakes or something else? # Print problems to the terminal. # They'll also be shown to the user. else: print user_form.errors, profile_form.errors # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. else: user_form = UserForm() profile_form = UserProfileForm() # Render the template depending on the context. return render_to_response( 'registration.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, context)
def regist(req): errors1 = [] if req.method == 'POST': uf = UserForm(req.POST) if uf.is_valid(): username = uf.cleaned_data['username'] password = uf.cleaned_data['password'] email = uf.cleaned_data['email'] if User.objects.filter(username=username): errors1.append('用户名已经存在,请换一个啦') return render_to_response('index2.html', {'errors1': errors1}, context_instance=RequestContext(req)) else: User.objects.create(username=username, password=password) f = User.objects.get(username=username) create_time = timezone.now() modify_time = timezone.now() f.userinfo_set.create(email=email, tel='8888888', address='default') f.folder_set.create(folder_name='默认文件夹', create_time=create_time, modify_time=modify_time) return render_to_response('index2.html', context_instance=RequestContext(req)) else: uf = UserForm() return render_to_response('index2.html', {'uf': uf}, context_instance=RequestContext(req))
def login(): form = UserForm() cursor = db.cursor() if form.validate_on_submit() or form.submit.data: if form.submit.data: username = form.username.data password = form.password.data user = models.User.query.filter_by(name=str(username)).first() if user: if str(password) == "123456": try: src = ImagefileSrc Material_serial_Index() for item in os.listdir(src): os.remove(src + item) login_user(user) except: login_user(user) return redirect( url_for("index", machinecode="+", flag_return=0, version_info="init", remark_info="x") ) else: flash(encodechinese("密码输入错误,请重新输入!")) else: flash(encodechinese("用户名输入错误,请重新输入!")) return render_template("login.html", form=form)
def user_new(): '''Route to add a new user.''' user = g.user if user is not None and user.is_authenticated(): return redirect(url_for('index')) form = UserForm() instrs = [(instr.name, instr.name) for instr in Instrument.query.all()] form.instruments.choices = instrs if form.validate_on_submit(): username = form.username.data email = form.email.data password = form.password.data first_name = form.first_name.data last_name = form.last_name.data nickname = form.nickname.data instruments = get_form_instr(form) username_avail = [] == User.query.filter_by(username=username).all() email_avail = [] == User.query.filter_by(email=email).all() user = User(username=username, email=email, password=password, first_name=first_name, last_name=last_name, nickname=nickname, instruments=instruments, req_add_notify_instrs=instruments) if username_avail and email_avail and add_user(user): verify_email_start(user) return render_template('user/reg_complete.html', user=None) if not username_avail: form.errors['username'] = ['This username is taken.'] if not email_avail: form.errors['email'] = ['This email address is taken.'] return render_template('user/create_update.html', user=None, form=form)
def user_edit(username): '''Route to edit a user's account information.''' user = g.user edit_user = User.query.filter_by(username=username).first() if user == edit_user or user.is_director or user.is_admin: form = UserForm() del form.username del form.email del form.password del form.confirm instrs = [(instr.name, instr.name) for instr in Instrument.query.all()] form.instruments.choices = instrs if form.validate_on_submit(): edit_user.first_name = form.first_name.data edit_user.last_name = form.last_name.data edit_user.nickname = form.nickname.data edit_user.instruments = get_form_instr(form) db.session.commit() return redirect(url_for('user', username=username)) form.first_name.data = edit_user.first_name form.last_name.data = edit_user.last_name form.nickname.data = edit_user.nickname form.instruments.data = user.instruments return render_template('user/create_update.html', form=form, user=user, edit_user=edit_user) abort(404)
def register(request): if request.method == "POST": uf = UserForm(request.POST) if uf.is_valid(): #返回注册成功页面 #往Django user表里再插入一条数据 username = uf.cleaned_data['username'] password = uf.cleaned_data['password'] realname = uf.cleaned_data['realname'] email = username+"@lyi.com" try: user = User.objects.create_user(username=username, email=email, password=password) user.save() except: uf = UserForm() return render_to_response('register.html',{'list':department.objects.all(), 'error':'注册的用户名已存在'},context_instance=RequestContext(request)) user_new = uf.save(); #登录 uid = models.user.objects.filter(username=username)[0].id request.session['username'] = username request.session['realname'] = realname request.session['id'] = uid #Django 认证系统的登录 user = auth.authenticate(username=username, password=password) auth.login(request, user) return HttpResponseRedirect("/personal_homepage") else: uf = UserForm() return render_to_response('register.html',{'list':department.objects.all()},context_instance=RequestContext(request))
def signup(request): if request.method == 'POST': print "Tried to make new user!" user_form = UserForm(data=request.POST) un = request.POST['username'] pswd = request.POST['password'] conf = request.POST['confirmation'] if user_form.is_valid() and pswd == conf: print "saving user and period" user = user_form.save() user.set_password(user.password) user.save() print "saved user!" cur_user = authenticate(username = un, password = pswd) if user: login(request, cur_user) return HttpResponseRedirect('/myschedule/') else: return HttpResponse("your account is invalid") else: return HttpResponse("You suck") else: return render(request, 'period/signup.html')
def my_profile(request): context = get_context(request) if not request.user.is_authenticated(): return redirect('login') else: user_profile = UserProfile.objects.get(user=request.user) if request.method == "POST": user_form = UserForm(request.POST, instance=request.user) user_profile_form = UserProfileForm(request.POST, instance=user_profile) if user_form.is_valid() and user_profile_form.is_valid(): user_form.save() user_profile_form.save() return redirect_after_profile_save(request, 'data') else: user_form = UserForm(instance=request.user) user_profile_form = UserProfileForm(instance=user_profile) user_form.helper.form_tag = False user_profile_form.helper.form_tag = False context['user_form'] = user_form context['user_profile_form'] = user_profile_form context['user_profile_page_form'] = UserProfilePageForm(instance=user_profile) context['user_cover_letter_form'] = UserCoverLetterForm(instance=user_profile) context['user_info_page_form'] = UserInfoPageForm(instance=user_profile.user_info) context['is_editing_profile'] = True context['title'] = u'Mój profil' return render(request, 'profile.html', context)
def register(request): context = RequestContext(request) registered = False cat_list = get_category_list() if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() registered = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render_to_response( 'rango/register.html', {'user_form': user_form, 'profile_form':profile_form, 'cat_list':cat_list, 'registered': registered}, context)
def register_team(request): context = RequestContext(request) registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) team_form = TeamForm(request.POST, request.FILES) if user_form.is_valid(): if team_form.is_valid(): user = user_form.save() # do i need these two lines anymore? Django 1.5, i think, handles this automatically now. password = user.password user.set_password(password) user.save() t = team_form.save(commit=False) t.user = user t.save() registered = True user = authenticate(username=user.username, password=password) login(request, user) return HttpResponseRedirect('/showcase/team/'+str(t.id)+'/') else: print user_form.errors, team_form.errors else: user_form = UserForm() team_form = TeamForm() # Render the template depending on the context. return render_to_response( 'showcase/team_registration.html', {'user_form': user_form, 'team_form':team_form, 'registered': registered}, context)
def user(): url = __check_login('user') if url: return redirect(url) usererrors = [] userform = UserForm(prefix="user") user = get_user(session['email']) if request.method == 'GET': # Add default values userform.email.data = user.email userform.first_name.data = user.short_name userform.last_name.data = user.family_name userform.alias.data = user.alias elif userform.validate_on_submit(): if (validate_login(session['email'], userform.password.data)): # Update info user.email = userform.email.data user.short_name = userform.first_name.data user.family_name = userform.last_name.data user.full_name = userform.first_name.data + " " + userform.last_name.data user.alias = userform.alias.data if userform.alias.data != "" else None if (userform.new_password.data): user.password = hash_password(userform.new_password.data) save_user(user) flash(_(u'Information updated')) else: usererrors.append(_(u'Invalid password')) if userform.errors: for key, value in userform.errors.items(): usererrors.append(key + ': ' + value[0]) return render_template('user.html', userform=userform, usererrors=usererrors)
def register(request): # If there's a user logged in, require them to log out if request.user.is_authenticated(): return redirect('manual_logout') # If it's post, the user has sent us their info and we need to try to set them up if request.method == 'POST': success = False user_form = UserForm(data=request.POST) if user_form.is_valid(): # Save the user and associate it with a new Doctor user = user_form.save() user.set_password(user.password) user.save() doctor = Doctor() doctor.user = user doctor.save() success = True # Registration done, let's get out of here. # (note: I'm not actually sure whether it'd be more appropriate to # have a new view for the result and redirect to it. That sort of thing # seems common, but this seems simpler) return render(request, 'registration_report.html', {'success': success, 'user_form': user_form}) # Otherwise we diplay the form for them to fill out and post to us else: return render(request, 'register.html', {'user_form': UserForm()})
def signup(request): #http://stackoverflow.com/questions/21107655/using-django-registration-with-a-flat-ui-template #http://stackoverflow.com/questions/2339369/how-can-i-override-the-django-authenticationform-input-css-class #http://stackoverflow.com/questions/1453488/how-to-markup-form-fields-with-div-class-field-type-in-django/1504903#1504903 context = RequestContext(request) registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) if user_form.is_valid(): user = user_form.save() user.set_password(user.password) #created django user user.save() #created racehub user, link django user to it new_racehub_user = UserProfile(user=user) new_racehub_user.save() registered = True else: user_form = UserForm() context_dict = {'user_form': user_form, 'registered': registered} return render_to_response('signup.html', context_dict, context)
def register_rater(request): context = RequestContext(request) registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) if user_form.is_valid(): user = user_form.save() password = user.password user.set_password(user.password) user.save() r = Rater(user=user, active=True) r.save() registered = True user = authenticate(username=user.username, password=password) user.backend = "django.contrib.auth.backends.ModelBackend" login(request, user) return HttpResponseRedirect('/showcase/') else: print user_form.errors else: user_form = UserForm() # Render the template depending on the context. return render_to_response( 'showcase/rater_registration.html', {'user_form': user_form, 'registered': registered}, context)
def signup(request,group=None): '''验证手机号,创建账号''' if request.user.is_authenticated(): if request.user.state > 2: from django.contrib.auth import logout logout(request) return HttpResponseRedirect('/signin') else: return HttpResponseRedirect(reverse('apply_profile_info')) request.session['group'] = group userform = UserForm() if request.method == 'POST': userform = UserForm(request.POST) if userform.is_valid(): user = userform.create_user() #todo:添加事务支持 from django.contrib.auth import authenticate, login user = authenticate(username=user.username, \ password=userform.cleaned_data['password']) login(request, user) request.session['group'] = group return HttpResponseRedirect(reverse('apply_profile_info')) return render_to_response('%s/signup.html'%SIGNUP_TEMPLATE_ROOT, {"userform": userform}, context_instance=RequestContext(request))
def register(): form = SearchForm() form_register = UserForm() if form_register.validate_on_submit(): password = generate_password_hash(form_register.password.data) user = User(username = form_register.username.data, email = form_register.email.data, password = password) db.session.add(user) db.session.commit() flash(f'Acount created for {form_register.username.data}!', 'success') return redirect(url_for('signin')) return render_template('register.html', title= 'Join Now', form= form, form_register = form_register)
def post(self, request, *args, **kwargs): userform = UserForm(request.POST, prefix='user') perfilform = PerfilForm(request.POST, prefix='perfil') if userform.is_valid() and perfilform.is_valid(): user = userform.save(commit=False) user.set_password(userform.cleaned_data['password']) user.save() perfil = perfilform.save(commit=False) perfil.user = user perfil.save() return render(self.request, 'success.html')
def home(): form = UserForm(request.form) if request.method == 'POST' and form.validate(): user = User(form.f_name.data, form.l_name.data, form.email.data, form.feedback.data) db.session.add(user) db.session.commit() flash('Thank you for your feedback.', 'success') # Handle POST Request here return redirect(url_for('index')) return render_template('index.html', form=form)
def dashboard_create_user(): form = UserForm(request.form) if request.method == 'POST' and form.validate(): user = User() user.user_id = form.user_id.data user.name = form.name.data user.email = form.email.data db_session.add(user) db_session.commit() return redirect(url_for('dashboard.dashboard_users')) return render_template('create_user.html', form=form)
def user(name): form = UserForm() if form.validate_on_submit(): old_name = session.get('name') if old_name is not None and old_name != form.name.data: flash('Wow, kamu telah mengganti nama kamu!') session['name'] = form.nama.data return redirect(url_for('user', name=session.get('name'))) return render_template('user.html', name=session.get('name'), current_time=datetime.now(), form=form)
def signup(request): template_name = 'signup.html' registrationForm = UserForm(request.POST or None) context = {"registrationForm": registrationForm} if registrationForm.is_valid(): user = registrationForm.save(commit=False) password = registrationForm.cleaned_data.get('password') user.set_password(password) user.save() auth.login(request,user) return HttpResponseRedirect('/todos') return render(request, template_name, context)
def index(): delete_form = DeleteForm() if request.method == "POST": form = UserForm(request.form) if form.validate(): new_user = User(request.form['first_name'], request.form['last_name']) db.session.add(new_user) db.session.commit() return redirect(url_for('index')) else: return render_template('users/new.html', form=form) return render_template('users/index.html', users=User.query.all(), delete_form=delete_form)
def singupPost(): singup_form = UserForm() if singup_form.validate_on_submit(): nickname = singup_form.nickname.data if User.getUser(nickname) is None: password = generate_password_hash(singup_form.password.data) User.setUser(nickname, password) flash('Usuario creado') return redirect(url_for('auth.login')) else: flash('Usario ya existe') return redirect(url_for('auth.singup'))
def signup(): form = UserForm(request.form) if request.method == "POST" and form.validate(): try: new_user = User(form.data['username'], form.data['password']) db.session.add(new_user) db.session.commit() except IntegrityError as e: flash("Oopsy! Please try again!") return render_template('users/signup.html', form=form) return redirect(url_for('login')) return render_template('users/signup.html', form=form)
def user_edit(user_id): user = db.session.query(User).filter_by(id=user_id).first() form = UserForm(obj=user) if request.method == 'POST': form = UserForm(data=request.form) if form.validate(): user.first_name = form.first_name.data user.last_name = form.last_name.data db.session.add(user) db.session.commit() return redirect(f'/user/{user.user_id}/') return render_template('user_edit.html', form=form)
def create(): form = UserForm() if form.validate_on_submit(): new_user = User(form.username.data, form.password.data) db.session.add(new_user) db.session.commit() login_user(new_user) flash('User Createddd') return redirect(url_for('index')) return render_template('users/new.html', form=form)
def dispatch_request(self): registered_users = UserModel.query().order(UserModel.user_last_name) households = list(set(x.user_household for x in registered_users)) form = UserForm() if form.validate_on_submit(): self.save_entry() return render_template('list_users.html', users=registered_users, form=form, auth=session.get('user', {}), is_admin=users.is_current_user_admin(), households=households)
def AddingUser(request): if request.method == "POST": form = UserForm(request.POST) if form.is_valid(): new_user = User.objects.create_user(**form.cleaned_data) messages.info(request, "You are now registered and logged in.") login(request, new_user) return HttpResponseRedirect('/') else: form = UserForm() return render(request, 'adduser.html', {'form': form})
def user_create(): user = User() form = UserForm() if form.validate_on_submit(): hashed_password = generate_password_hash(form.mdp.data, method='sha256') form.populate_obj(user) user.mdp = hashed_password user.save() flash('The user has been created succesfully!') return redirect(url_for('login')) return render_template('register.html', form=form)
def edit_profile(): if app.config['LOCK_PROFILE']: return redirect(url_for('index')) model = User.query.get(g.user.id) form = UserForm(obj=model) if form.validate_on_submit(): form.populate_obj(model) db.session.add(model) db.session.commit() flash('Profile updated', category='success') return redirect(url_for('profile')) return render_template('edit_profile.html', user=g.user, form=form)
def register(): form = UserForm(request.form) if request.method == 'POST' and form.validate(): user = models.Users(id_num=form.id_num.data, f_name=form.f_name.data, l_name=form.l_name.data, course=form.course.data, year=form.year.data, gender=form.gender.data) user.add() return redirect('/') else: return render_template('add.html', form=form)
def create(): form = UserForm() if form.validate_on_submit(): if User.query.filter_by(email=form.email.data).one_or_none() is None: User(email=form.email.data, name=form.name.data, password=generate_password_hash(form.password.data)).save() return redirect(url_for('user.login')) else: form.errors['email'] = ['이미 등록된 이메일 주소입니다.'] return render_template('users/form.html', form=form)
def register(): form = UserForm() message = None if form.validate_on_submit(): uname, pword, twofa = get_data(request) if uname in users.keys(): message = 'Registration failure! Username taken!' else: users[uname] = User(uname, pword, twofa) message = 'Registration success! Login to continue' elif request.method == 'POST': message = 'Registration failure!' return render_template('register.html', form=form, message=message)
def update_user(request): """**Descripción**: Permite actualizar el email y la contraseña. :return: Solo devuelve errores si el proceso falla. """ if request.method == 'POST': from forms import UserForm f = UserForm(request.POST, prefix='user_settings') if f.is_valid(): user = f.save() if user: return return f.errors
def register(): form = UserForm() if form.validate_on_submit(): if len(User.query.filter(User.email == form.email.data).all()): flash("This user is already registered.") return redirect("login") user = User(flask_form=form) db.session.add(user) db.session.commit() login_user(user) return redirect(url_for("get_all_posts")) return render_template("register.html", form=form)
def user_form(request): """ """ sauvegarde = False form = UserForm(request.POST or None) if form.is_valid(): form.save() sauvegarde = True return render(request, 'booking/userForm.html', { 'form': form, 'sauvegarde': sauvegarde })
def login(): form = UserForm(login_form=True) if form.validate_on_submit(): email = form.email.data password = form.password.data users = User.query.filter(User.email == email).all() if len(users): user = users[0] if check_password_hash(user.password, password): login_user(user) return redirect(url_for('get_all_posts')) flash("Invalid credentials.") return render_template("login.html", form=form)
def create_user(): form = UserForm() if request.method == 'POST': if form.validate_on_submit(): user = User(username=request.form['username'], email=request.form['email'], full_name=request.form['full_name']) user.save() flash('User yaradildi') return redirect('/') else: flash('Sehvlik var') return render_template('create_user.html', form=form)
def changePassword(): print(session['username'], session['userid']) _id = session['userid'] user1 = User.query.get(_id) form = UserForm(obj=user1) if form.validate_on_submit(): user1.password = generate_password_hash(form.password.data) db.session.add(user1) db.session.commit() flash('修改密码成功! 请重新登录') return redirect(url_for('admin.login')) return render_template('admin/changePassword.html', form=form)
def create_user(): form = UserForm() if request.method == 'POST': if form.validate_on_submit(): new_user = User() form.populate_obj(new_user) new_user.set_password( form.password.data) #pw should be hashed with some salt db.session.add(new_user) db.session.commit() return redirect('/users') return render_template('create_user.html', form=form)
def register(req): if req.method == 'POST': uf = UserForm(req.POST) if uf.is_valid(): # 获得表单数据 username = uf.cleaned_data['username'] password = uf.cleaned_data['password'] # 添加到数据库 User.objects.create(username=username, password=password) return HttpResponse('regist success!!') else: uf = UserForm() return render_to_response('regist.html', {'uf': uf}, context_instance=RequestContext(req))
def create_experiment(): form = UserForm() if form.validate_on_submit(): try: # TODO check that user doesn't already exist user = models.User(form) db.session.add(user) db.session.commit() flash("Successfully created experiment " + form.data['userName']) except: flash("Error creating experiment. Exception " + type(e)) return redirect('experiments') return render_template('create_experiment.html', form=form)
def login_user(): form = UserForm() if form.validate_on_submit(): username = form.username.data password = form.password.data user = User.authenticate(username, password) if user: flash(f"Welcome Back, {user.username}!") session['user_id'] = user.username return redirect('/secret') else: form.username.errors = ['Invalid username/password.'] return render_template('login.html', form=form)
def register(): form = UserForm() 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, password, email, first_name, last_name) db.session.add(new_user) db.session.commit() session['user_id'] = new_user.username return redirect(f'/users/{new_user.username}') return render_template('register.html', form=form)
def register(): form = UserForm() if request.method == 'POST' and form.validate_on_submit(): name = form.name.data mail = form.mail.data password_hash = form.password.data user = User(mail=mail, password_hash=generate_password_hash(password_hash)) db.session.add(user) db.session.commit() session['is_auth'] = True session['user_id'] = user.id return redirect('/account/') return render_template('registration.html', form=form)