def profile(): if 'email' not in session: return redirect(url_for('signin')) user = User.query.filter_by(email=session['email']).first() profile = Profile.query.filter_by(uid=user.uid).first() form = ProfileForm(obj=profile) form.updateHeaderData(profile, user) if request.method == 'POST': if form.validate() == False: return render_template('profile.html', form=form) else: profile.updateData( user.uid, form.cpf.data, form.rg.data, form.address.data, int(form.number.data), form.additionalInformation.data, form.district.data, form.region.data, form.country.data, form.telephone.data, form.cellphone.data, form.profileType.data, form.role.data, form.bloodType.data) db.session.commit() return redirect(url_for('profile')) elif request.method == "GET": if user is None: return redirect(url_for('signin')) else: return render_template('profile.html', form=form)\
def profile(): form = ProfileForm(request.form) if request.method == 'POST' and form.validate(): #need to set up salalchemy and reset the redirect to a #different url_fo() return redirect(url_for('profile')) return render_template('profile.html', form=form)
def post(self): user = tusers.get_current_user() if user: form = ProfileForm(self.request.POST) if (form.validate()): user.full_name = form.name.data user.current_institution = form.institution.data user.public_profile = form.public.data user.phone = form.phone.data user.put() if form.email.data: user.change_email(form.email.data) if form.email_code.data: user.verify_email(form.email_code.data) self.redirect('/update_profile') else: template_values = { 'user' : user, 'logout' : tusers.create_logout_url('/'), 'form' : form } template = JINJA_ENVIRONMENT.get_template('view/update_profile.html') self.response.write(template.render(template_values)) else: self.redirect(tusers.create_login_url(self.request.uri))
def land(): form = ProfileForm(request.form) if request.method == 'POST' and form.validate(): studentid = form.data['studentid'] name = form.data['name'] gender = form.data['gender'] gradyear = form.data['gradyear'] try: session.execute( "insert into students (studentid, name, gender, gradyear) values (:studentid, :name, :gender, :gradyear)", { 'studentid': studentid, 'name': name, 'gender': gender, 'gradyear': gradyear }) session.commit() except exc.SQLAlchemyError: return render_template( 'error.html', error='Uh oh - it looks like that RUID is already registered.', link="/create", destination='back') return render_template( 'student.html', name=name, ruid=studentid, reviews=[], confirmation='Partner has been added to database!') return render_template('create_profile.html', form=form)
def profile(): user = User.query.filter_by(email=session['email']).first() if user is None: return redirect(url_for('signin')) form = ProfileForm(language=user.lang) session['room'] = 'General' form.language.choices = [(g.uid, g.name) for g in Language.query.order_by('name')] if 'email' not in session: return redirect(url_for('signin')) if request.method == 'POST': if form.validate() == False: return render_template('profile.html', form=form, user=user) else: user.firstname = form.firstname.data user.lastname = form.lastname.data user.lang = form.language.data db.session.commit() return redirect(url_for('profile')) if request.method == 'GET': return render_template('profile.html', form=form, user=user)
def profile_add(): form = ProfileForm(request.form) if request.method == 'GET': return render_template('profile_add.html',form=form) if form.validate() and request.method == 'POST': first_name = request.form['first_name'] last_name = request.form['last_name'] age = request.form['age'] file = request.files['image'] username = request.form['username'] sex = request.form['sex'] filename = file.filename file.save(os.path.join('app/static/uploads', filename)) # write the information to the database newprofile = Myprofile(first_name=first_name, last_name=last_name, age=age, sex=sex, username=username, image='/static/uploads/'+filename) db.session.add(newprofile) db.session.commit() return "{} {} was added to the database".format(request.form['first_name'], request.form['last_name']) return render_template('profile_add.html',form=form)
async def profile(request): form = ProfileForm(request) if request.method == 'POST': avatar_path = '' if form.validate(): image = form.avatar.data intro = form.intro.data github_url = form.github_url.data linkedin_url = form.linkedin_url.data avatar_path = image.name uploaded_file = Path( request.app.config.UPLOAD_FOLDER) / avatar_path uploaded_file.write_bytes(image.body) form.avatar_path.data = avatar_path kw = {'intro': intro, 'github_url': github_url, 'linkedin_url': linkedin_url} if avatar_path: kw.update(avatar=avatar_path) await set_profile(**kw) if not avatar_path: form.avatar_path.data = (await get_profile()).avatar elif request.method == 'GET': profile = await get_profile() form.intro.data = profile.intro form.github_url.data = profile.github_url form.linkedin_url.data = profile.linkedin_url form.avatar_path.data = profile.avatar return {'form': form}
async def profile(request): if not SHOW_PROFILE: return response.json({'on': False}) if request.method == 'PUT': profile = {'avatar': ''} form = ProfileForm(request) if form.validate(): intro = form.intro.data avatar = form.avatar.data github_url = form.github_url.data linkedin_url = form.linkedin_url.data profile = { 'intro': intro, 'github_url': github_url, 'linkedin_url': linkedin_url } if avatar: profile.update(avatar=avatar) await Profile.set(**profile) if not profile.get('avatar'): try: profile['avatar'] = (await Profile.get()).avatar except AttributeError: ... elif request.method == 'GET': profile = await Profile.get() avatar = profile.get('avatar') if avatar: profile['avatar_url'] = request.app.url_for( 'static', filename=f'upload/{avatar}') else: profile['avatar_url'] = '' return response.json({'on': True, 'profile': profile})
def profile(): form = ProfileForm() if request.method == 'POST': form = ProfileForm(request.form) if form.validate(): current_user.set_password(form.new_password.data) current_user.save() flash({'type': 'success', 'text': 'Password updated'}) return redirect('/') return render_template("/auth/profile.html", **locals())
def profile(): form = ProfileForm() if request.method == 'POST': form = ProfileForm(request.form) if form.validate(): current_user.set_password(form.new_password.data) current_user.save() flash({'type':'success', 'text':'Password updated'}) return redirect('/') return render_template("/auth/profile.html", **locals())
def post(self): form = ProfileForm(self.request.POST) success_message = '' if form.validate(): self.save_profile() form = ProfileForm() success_message = 'Your request submited successfully' template = JINJA_ENVIRONMENT.get_template(self.get_template_name()) template_value = self.get_template_values() template_value['success_message'] = success_message self.response.write(template.render(template_value))
def profile(): form = ProfileForm(request.form) user = Users.query.filter_by(username=session['username']).first() if request.method == 'POST' and form.validate(): user.email = form.email.data user.city = form.city.data user.password = sha256_crypt.encrypt(str(form.password.data)) session['city'] = form.city.data db.session.commit() flash('Your account settings have been updated.', 'success') return redirect(url_for('profile')) return render_template('profile.html', user=user, form=form)
def account(): form = ProfileForm(request.form) if request.method == 'GET': form.populateForm(current_user) if request.method == 'POST' and form.validate(): current_user.first_name = form.first_name.data current_user.email = form.email.data current_user.phone = form.phone.data current_user.show_whats = form.show_whats.data current_user.can_email = form.can_email.data db.session.commit() flash('Conta atualizada', 'success') return redirect(url_for('index')) return render_template('account.html', form=form)
def profile(): user = Student.query.get(g.user.username) if request.method == 'GET': return render_template('student/profile.html', user=user) form = ProfileForm(request.form) if form.validate(): form.save() flash(u"资料成功更新!") user = Student.query.get(g.user.username) render_template('student/profile.html', user=user) for fieldName, errorMessages in form.errors.iteritems(): for err in errorMessages: flash(err) return render_template('student/profile.html', user=user)
def profile(): user = Student.query.get(g.user.username) if request.method == 'GET': return render_template('student/profile.html',user=user) form = ProfileForm(request.form) if form.validate(): form.save() flash(u"资料成功更新!") user = Student.query.get(g.user.username) render_template('student/profile.html',user=user) for fieldName, errorMessages in form.errors.iteritems(): for err in errorMessages: flash(err) return render_template('student/profile.html',user=user)
def profileedit(): form = ProfileForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('profileedit.html', form=form) else: profile = Profile(form.picture,form.home_address,form.gender,form.first_name ,form.middle_name,form.last_name,form.weapon_of_choice ,form.height,form.weight,form.build,form.complexion,form.hair_colour ,form.eye_colour ,form.ethnicity ,form.scars ,form.work_address ,form.work_contact_no,form.job_title ,form.mother_first_name ,form.mother_maiden_name,form.mother_surname,form.mother_address,form.mother_nationality,form.father_first_name,form.father_surname ,form.father_address,form.father_nationality,form.date_create) db.session.add(profile) db.session.commit() return 'Form posted.' elif request.method == 'GET': return render_template('profileedit.html', form=form)
def profile(profile_id=None): msg = '' p = get_user() if profile_id: p = User.query.get(profile_id) form = ProfileForm(request.form) if request.method == 'POST': if not form.validate(): return render_template('profile.html', user=get_user(), profile=p, form=form, msg=msg) else: u = get_user() u.display_name = form.display_name.data u.email = form.email.data db.session.commit() msg = "profile upadted!" return render_template('profile.html', user=get_user(), profile=p, form=form, msg=msg)
def profile(): # must be signed in if 'user_id' not in session: return redirect(url_for('signin')) profile = ProfileForm() if request.method == "GET": # get user data qry = db.session.execute(""" select user_id, first_name, last_name, email, SUBSTR(username,2) as username, create_ts from users where user_id = :user """, {'user': int(session['user_id'])}) user = qry.first() # profile form profile.first_name.default = user.first_name profile.last_name.default = user.last_name profile.email.default = user.email profile.username.default = user.username profile.create_ts.default = user.create_ts profile.process() return render_template('users/profile.html', form=profile) elif request.method == "POST": if profile.validate() == False: return render_template('users/profile.html', form=profile) else: User.query.filter_by(user_id=int(session['user_id'])).update( dict( first_name = profile.first_name.data, last_name = profile.last_name.data, email = profile.email.data, username = '******' + profile.username.data ) ) db.session.commit() return redirect(url_for('index'))
def create_user(user_id=None): """ Create or edit a user. """ form = ProfileForm() if request.method == 'POST': if form.validate(): if user_id != None: # Edit a user user = User.query.filter(User.id == user_id).first() form.populate_obj(user) if form.password.data != "": user.set_password(form.password.data) db.session.commit() flash('User "' + user.firstname + '" successfully updated.', 'success') else: # Create a new user role_user = Role.query.filter(Role.name == "user").first() user = User(firstname=form.firstname.data, lastname=form.lastname.data, email=form.email.data, pwdhash=generate_password_hash(form.password.data)) user.roles.extend([role_user]) db.session.add(user) try: db.session.commit() except IntegrityError: flash('Email already used.', 'warning') return redirect(redirect_url()) flash('User "' + user.firstname + '" successfully created.', 'success') return redirect("/admin/edit_user/"+str(user.id)+"/") else: return render_template('profile.html', form=form) if request.method == 'GET': if user_id != None: user = User.query.filter(User.id == user_id).first() form = ProfileForm(obj=user) message = "Edit the user <i>" + user.firstname + "</i>" else: form = ProfileForm() message="Add a new user" return render_template('/admin/create_user.html', form=form, message=message)
def info(): user_id = g.current_login_id user_profile = g.db.query(UserProfile).filter(UserProfile.user_id==user_id).one() if request.method == "POST": form = ProfileForm(request.form) if form.validate(): try: user_profile.company_name = form.company_name.data user_profile.contact_name = form.contact.data user_profile.mobile = form.mobile.data user_profile.company_addr = form.addr.data g.db.flush() success = u"修改用户资料成功" except Exception, e: log.error(e.message) g.db.rollback() errors = [u"未知异常",] else: errors = [v[0] for k, v in form.errors.iteritems()]
def profile(): form = ProfileForm(request.form) if request.method == 'POST' and form.validate(): file = request.files['picture'] if file: file_folder = app.config['UPLOAD_FOLDER'] filename = secure_filename(file.filename) file.save(os.path.join(file_folder, filename)) name = filename else: name = 'default.jpg' user = Profile(form.username.data, form.firstname.data, form.lastname.data, form.age.data, form.bio.data, name, form.gender.data) db.session.add(user) db.session.commit() flash('User created successfully') return redirect(url_for('home')) return render_template('signup.html', form=form)
def profile(): if login() is True: return redirect(url_for('start.index')) customer = Customer.query.get(session['customer_id']) profileform = ProfileForm() # upate profile if request.form: form = ProfileForm(request.form) if request.method == 'POST' and form.validate(): update = Customer( form.first_name.data, form.last_name.data, form.email.data, form.password.data ) if db.session.commit(update): flash("Profile updates succesfully") return render_template('customer/profile.html', customer=customer, profileform=profileform)
def create_profile(): user_id = request.form['user_id'] name = request.form['name'] surname = request.form['surname'] birthdate = request.form['birthdate'] website = request.form['website'] address = request.form['address'] telephone = request.form['telephone'] description = request.form['description'] profform = ProfileForm(name, surname, birthdate, website) errors = profform.validate() if errors: return json.dumps({'success': False, "errors": errors}) from models.users import Profile image = "" newProfile = Profile(user_id, name, surname, birthdate, website, address, telephone, description, image) db.session.add(newProfile) db.session.commit() return json.dumps({"success": True})
def cuenta_view(): """ Function to display the form that allows to query and modify the user profile """ form = ProfileForm(request.form) user = Usuarios.objects(id=login.current_user.get_id()).first() if request.method == 'POST': user.usuario = form.usuario.data user.nombre = form.nombre.data user.apellidos = form.apellidos.data user.password = form.password.data user.email = form.email.data save = False if form.validate(): save = True user.save(clean=False) return render_template("user/profile.html", user=user, form=form, save=save) return render_template('user/profile.html', user=user, form=form)
def profile(): text = db_queries.get_page_content('profile') if request.method == 'POST': #if the submit button was hit, loads the information into the form form = ProfileForm(request.form) if form.validate(): #sends the user to the profile/edit profile page with updated information # if is_profile_changed(form): # #user profile has been changed, update the database db_posts.update_profile(form, current_user.primary_email) text = db_queries.get_page_content('profile') profile = db_queries.get_profile(current_user.primary_email) return render_template("my_profile.html", text=text, profile=profile, form=form, leftProfileContent=profile) else: profile = db_queries.get_profile(current_user.primary_email) return render_template("my_profile.html", text=text, profile=profile, form=form, leftProfileContent=profile) #sends the user to the profile/edit profile page for GET methods profile = db_queries.get_profile(current_user.primary_email) form = ProfileForm(obj=profile) return render_template("my_profile.html", text=text, profile=profile, form=form, leftProfileContent=profile)
def profile(): """ Edit the profile of the currently logged user. """ user = User.query.filter(User.email == g.user.email).first() form = ProfileForm() if request.method == 'POST': if form.validate(): form.populate_obj(user) if form.password.data != "": user.set_password(form.password.data) db.session.commit() flash('User "' + user.firstname + '" successfully updated.', 'success') return redirect(url_for('profile')) else: return render_template('profile.html', form=form) if request.method == 'GET': form = ProfileForm(obj=user) return render_template('profile.html', user=user, form=form)
def info(): user_id = g.current_login_id user_profile = g.db.query(UserProfile).filter( UserProfile.user_id == user_id).one() if request.method == "POST": form = ProfileForm(request.form) if form.validate(): try: user_profile.company_name = form.company_name.data user_profile.contact_name = form.contact.data user_profile.mobile = form.mobile.data user_profile.company_addr = form.addr.data g.db.flush() success = u"修改用户资料成功" except Exception, e: log.error(e.message) g.db.rollback() errors = [ u"未知异常", ] else: errors = [v[0] for k, v in form.errors.iteritems()]
def profile(): form = ProfileForm() if request.method == 'POST': if form.validate() == False: return render_template('profile.html', form=form) else: user = db.session.query(User).filter_by(email=session['email']).first() if form.firstname.data: user.firstname = form.firstname.data if form.lastname.data: user.lastname = form.lastname.data if form.password.data: user.set_password(form.password.data) db.session.commit() return redirect(url_for('contacts')) elif request.method == 'GET': return render_template('profile.html', form=form)
def profile(): form = ProfileForm() if request.method == 'POST': if form.validate() == False: return render_template('profile.html', form=form) else: user = db.session.query(User).filter_by( email=session['email']).first() if form.firstname.data: user.firstname = form.firstname.data if form.lastname.data: user.lastname = form.lastname.data if form.password.data: user.set_password(form.password.data) db.session.commit() return redirect(url_for('contacts')) elif request.method == 'GET': return render_template('profile.html', form=form)
def change_profile(): form = ProfileForm() if form.validate(): try: user = g.user user.profile = form.profile.data user.fullname = form.fullname.data user.email = form.email.data user.birthday = form.birthday.data user.country = form.country.data user.state_province_region = form.state_province_region.data user.city = form.city.data user.occupation = form.occupation.data user.institution = form.institution.data user.agree_mailer = form.agree_mailer.data db.session.commit() flash(dictionary()["updated_profile"], "success") except: flash(dictionary()["500"], "danger") return render_template("user/edit.html", form=form)
def profile(user_id, page=1): user = User.query.get(user_id) if not user: return redirect(url_for('Common.index')) pagination = Article.query.filter_by(deleted=False, author=user).order_by(Article.id.desc())\ .paginate(page, per_page=10, error_out=True) form = ProfileForm(request.form) if request.method == 'POST' and form.validate(): profile = json.loads(user.verbose) if user.verbose else dict() profile['mail'] = form.mail.data profile['homepage'] = form.homepage.data profile['brief'] = form.brief.data user.verbose = json.dumps(profile) f = request.files['avatar'] if f: try: filename = save_file(f) user.avatar = filename except: pass user.save() profile = json.loads(user.verbose) if user.verbose else None kwargs = dict( user=user, profile_form=form, profile=profile, pagination=pagination, ) return render_template('user/profile.html', **kwargs)