def profile(): # 创建表单对象 form = ProfileForm() # 获取用户信息 u = User.query.filter_by(username=current_user.username).first() if form.validate_on_submit(): # 判断头像是否修改 if form.protrait.data: # 图片根路径 base_dir = os.path.join(current_app.config['UPLOAD_FOLDER'], 'static\image\\') # 若不是默认头像,则删除旧头像 if u.protrait != 'default.jpg': # 删除原图像 try: # 若不存在则会报错 os.remove(os.path.join(base_dir, u.protrait)) except: pass # 生成新图像名称 u.protrait = uuid.uuid4( ).hex + '.' + form.protrait.data.filename.split('.')[-1].lower() # 保存图片到本地 form.protrait.data.save(os.path.join(base_dir, u.protrait)) # 保存更新后的数据 u.nickname = form.nickname.data u.sex = dict(form.sex.choices).get(form.sex.data) u.info = form.info.data # 提交到数据库 db.session.add(u) db.session.commit() flash('保存成功') else: form.username.data = u.username form.email.data = u.email form.nickname.data = u.nickname if u.sex: form.sex.data = dict( zip( dict(form.sex.choices).values(), dict(form.sex.choices).keys())).get(u.sex) form.info.data = u.info return render_template('user/profile.html', form=form, filename=u.protrait)
def profile(): form = ProfileForm() if form.validate_on_submit(): fn = request.form['firstname'] ln = request.form['lastname'] em = request.form['email'] im = request.files['photo'] lo = request.form['location'] ge = request.form['gender'] bi = request.form['biography'] filename = secure_filename(im.filename) im.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) date = now.strftime("%m/%d/%Y") new = UserProfile(fn, ln, em, ge, lo, bi, filename, date) db.session.add(new) db.session.commit() flash('File Saved', 'success') return redirect(url_for('profiles')) return render_template("profile.html", form=form)
def profile(): form = ProfileForm() if form.validate_on_submit(): fname = request.form['first_name'] lname = request.form['last_name'] gender = request.form['gender'] email = request.form['email'] location = request.form['location'] biography = request.form['biography'] f = request.files['profile_pic'] filename = secure_filename(f.filename) f.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) new_prof = UserProfile(fname, lname, gender, email, location, biography, filename) db.session.add(new_prof) db.session.commit() flash('Profile Added', 'success') return redirect(url_for('list_profiles')) return render_template('profile.html', form=form)
def edit_profile(): form = ProfileForm() if form.validate_on_submit(): current_user.first_name = form.first_name.data current_user.last_name = form.last_name.data current_user.bio = form.bio.data current_user.company_name = form.company_name.data db.session.commit() flash('Your changes have been saved.') return redirect(url_for('profile')) elif request.method == 'GET': form.first_name.data = current_user.first_name form.last_name.data = current_user.last_name form.bio.data = current_user.bio form.company_name.data = current_user.company_name print(form.errors) return render_template('edit_profile.html', form=form, page='edit_profile')
def change_profile(request): user = request.user password_form = PasswordChangeForm(request.user) profile_form = ProfileForm(request.POST) if request.method == 'POST': if profile_form.is_valid(): user.email = request.POST['email'] user.save() messages.success(request, 'Your profile was successfully updated!') return HttpResponseRedirect(reverse('app:profile')) else: messages.error(request, 'Please correct the error below.') return render( request, 'app/profile/index.html', { 'user': user, 'password_form': password_form, 'profile_form': profile_form })
def profile(): form = ProfileForm() form.email.data = current_user.email context = { 'form': form } if form.validate_on_submit(): db_email = User.query.filter_by(email=form.email.data) if current_user.email == form.email.data: flash('You already own that email. No change needed') if db_email is not None and not db_email != current_user.email: flash("That email is already taken. Try again.") return redirect(url_for('profile')) current_user.email = form.email.data current_user.set_password(form.password.data) flash("Profile has been updated") db.session.commit() return redirect(url_for('profile')) return render_template('profile.html', **context)
def profile(username): user = query_db('SELECT * FROM Users WHERE username="******";'.format( session.get('username')), one=True) if user == None: flash('You are not logged in') return redirect(url_for('index')) elif user['password'] == session.get('password'): form = ProfileForm() if form.is_submitted(): user = query_db( 'SELECT * FROM Users WHERE username="******";'.format(username), one=True) if user == None: flash( 'you are not logged in. Every error shouldnt happen, but this error really extra shouldnt happen' ) return redirect(url_for('index')) elif user['password'] == session.get('password'): query_db( 'UPDATE Users SET education="{}", employment="{}", music="{}", movie="{}", nationality="{}", birthday=\'{}\' WHERE username="******" ;' .format(form.education.data, form.employment.data, form.music.data, form.movie.data, form.nationality.data, form.birthday.data, username)) else: flash( 'You are not logged in as that user you tried to edit the profile of' ) return redirect( url_for('stream', username=session.get('username'))) return redirect(url_for('profile', username=username)) user = query_db( 'SELECT * FROM Users WHERE username="******";'.format(username), one=True) return render_template('profile.html', title='profile', username=username, user=user, form=form) else: flash('You are not logged in') return redirect(url_for('index'))
def edit_profile(user_id): user = User.query.filter_by(id=user_id).first_or_404() if current_user != user: #sanity check return redirect(url_for('index')) form = ProfileForm() if form.validate_on_submit(): user.username = form.username.data user.nickname = form.nickname.data user.about_me = form.about_me.data db.session.commit() return redirect(url_for('view_profile', user_id=user.id)) elif request.method == 'GET': form.username.data = user.username form.nickname.data = user.nickname form.about_me.data = user.about_me return render_template('edit_profile.html', form=form, user=user)
def update_profile_pic(id): # find user by id user = User.query.get(id) # Make form and get csrf_token from request form = ProfileForm() form['csrf_token'].data = request.cookies['csrf_token'] # Validate form if form.validate_on_submit(): # find user by id user = User.query.get(id) # add form data to user user.bio = request.form.get("bio") user.street_address = request.form.get("street_address") user.city = request.form.get("city") user.state = request.form.get("state") user.zipcode = request.form.get("zipcode") user.updated_at = datetime.now() # checking if file was uploaded if len(request.files) > 0: file = request.files["file"] print(file.filename) print(type(file)) if check_file(file.filename): file_url = upload_file_to_s3(file, Config.S3_BUCKET) user.profile_image_url = file_url else: return { 'errors': ['Unaccepted file extension, must be JPG, PNG, or JPEG'] }, 400 db.session.commit() return user.to_dict() return {'errors': validation_errors_to_error_messages(form.errors)}, 400
def account_settings(): '''账户设置,包括改密码等''' user = current_user form = ProfileForm(request.form, user) if form.validate_on_submit(): #user.username = form['username'].data #user.gender = form['gender'].data user.homepage = form['homepage'].data.strip() if not user.homepage.startswith('http'): user.homepage = 'http://' + user.homepage user.description = form['description'].data.strip() if request.files.get('avatar'): avatar = request.files['avatar'] ok,info = handle_upload(avatar,'image') if ok: user.set_avatar(info) else: errors.append(_("Avatar upload failed")) user.save() return render_template('settings.html', user=user, form=form)
def profile(): form = ProfileForm(request.form) if request.method == 'POST': uploadedfile = request.files['uploadedfile'] if uploadedfile and allowed_file(uploadedfile.filename): uploadedfilename = form.username.data + '_' + secure_filename( uploadedfile.filename) filepath = os.path.join(os.getcwd() + '/app/static/uploads/', uploadedfilename) uploadedfile.save(filepath) user = User(uploadedfilename, form.username.data, form.firstname.data, form.lastname.data, form.age.data, form.sex.data, datetime.now()) db.session.add(user) db.session.commit() return redirect( '/profile/' + str(User.query.filter_by(username=user.username).first().id)) else: return render_template('profileform.html', form=form)
def profile(): form = ProfileForm() if form.validate_on_submit() and request.method == 'POST': firstname = form.first_name.data lastname = form.last_name.data gender = form.gender.data email = form.email.data location = form.location.data biography = form.biography.data photo = form.photo.data filename = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) created_on = format_date_joined() user = UserProfile(firstname,lastname,gender,email,location,biography,filename, date=created_on) db.session.add(user) db.session.commit() flash('Profile successfully creadted!') return redirect(url_for('profiles')) flash_errors(form) return render_template('profile.html', form=form)
def profile_edit(): user = User.find_by_id(bson_obj_id(current_user.id)) if not user: abort(404) form = ProfileForm() if request.method == 'POST': if form.validate_on_submit(): username = form.username.data location = form.location.data website = form.website.data introduction = form.introduction.data data = { 'username': username, 'location': location, 'website': website, 'introduction': introduction } avatar = request.files['avatar'] if avatar and AllowFile.is_img(avatar.filename): filename = secure_filename(avatar.filename) fs = GridFS(mongo.db, collection="avatar") avatar_id = fs.put(avatar, content_type=avatar.content_type, filename=filename) if avatar_id: if user['avatar']: fs.delete(bson_obj_id(user['avatar'])) data['avatar'] = avatar_id else: flash('图片格式不支持', 'red') User.update_user(user['_id'], data) return redirect(url_for('.profile')) else: flash('资料修改失败', 'red') return render_template('profile_edit.html', user=user, form=form, title='编辑资料')
def profile(): form = ProfileForm() if request.method == 'POST' and form.validate_on_submit(): firstname = form.firstname.data lastname = form.lastname.data email = form.email.data gender = form.gender.data location = form.location.data biography = form.biography.data profile_pic = form.profile_pic.data filename = secure_filename(profile_pic.filename) profile_pic.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) created_on = datetime.today().strftime('%Y-%m-%d') user = User(firstname, lastname, gender, email, location, biography, filename, created_on) db.session.add(user) db.session.commit() flash('Profile successfully added', 'success') return redirect(url_for('profiles')) flash_errors(form) return render_template('profile.html', form=form)
def account_page(): form = ProfileForm() if form.validate_on_submit(): if form.picture.data: picture_file = save_picture(form.picture.data) current_user.image_file = picture_file current_user.username = form.username.data current_user.email = form.email.data # db.session.add(current_user) db.session.commit() flash(f'Account info updated for {current_user.username} !', 'success') return redirect(url_for('account_page')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email image_file = url_for('static', filename='user_pics/' + current_user.image_file) return render_template('account.html', title='My Account', image_file=image_file, form=form)
def edit_profile(): form = ProfileForm() if form.validate_on_submit(): username = form.username.data email = form.email.data alarm_email = form.alarm_email.data try: g.user.username = username g.user.email = email g.user.alarm_email = alarm_email db.session.commit() return redirect(url_for('index')) except (InvalidRequestError, IntegrityError): flash('Duplicate username!') db.session.rollback() form.username.data = g.user.username form.email.data = g.user.email form.alarm_email.data = g.user.alarm_email return render_template('edit_profile.html', form=form)
def profile(): filefolder = UPLOAD_FOLDER form = ProfileForm(CombinedMultiDict((request.files, request.form))) if request.method == "POST": if form.validate_on_submit(): # Get the username and password values from the form. fname = form.fname.data lname = form.lname.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 gender = form.gender.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'] #user= UserProfile( fname, lname, location, email,bibliography,gender,file) user = UserProfile(fname, lname, location, email, biography, gender, file.filename, currentDate) db.session.add(user) db.session.commit() flash('User Added successfully.', 'success') return redirect(url_for('home')) else: flash("Try again") print(form.errors.items()) return render_template("profile.html", form=form)
def profile(): """Render the website's profile page""" form = ProfileForm() user_no = len(UserProfile.query.all()) if request.method == "POST" and form.validate_on_submit(): first_name = form.first_name.data last_name = form.last_name.data gender = form.gender.data location = form.location.data email = form.email.data bio = form.biography.data date = datetime.datetime.now() image = form.image.data imageName = first_name + last_name + str(user_no) + ".png" # file = form.upload.data # filename = secure_filename(file.filename) # file.save(os.path.join(app.config['UPLOAD_FOLDER'],filename)) new_user = UserProfile(first_name=first_name, last_name=last_name, gender=gender, location=location, email=email, biography=bio, created_on=date, profilePic=imageName) db.session.add(new_user) db.session.commit() image.save(os.path.join(app.config['UPLOAD_FOLDER'], imageName)) # image.save("app/static/profilepictures/" + imageName + ".png") flash("New User Profile Created", "success") return redirect(url_for("profiles")) return render_template("profile.html", form=form)
def add_user(): form = ProfileForm() if request.method == "POST" and form.validate_on_submit(): photo = form.photo.data filename = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) flash('Profile photo stored', 'success') user = UserProfile(form.firstName.data, form.lastName.data, form.gender.data, form.email.data, form.location.data, form.biography.data, filename) db.session.add(user) db.session.commit() flash('New user successfully added', 'success') return redirect(url_for('show_profiles')) return render_template("view.profile.html", form=form)
def profile(): form=ProfileForm() if request.method == "POST" and form.validate_on_submit(): username=form.username.data password=form.password.data firstname=form.firstname.data lastname=form.lastname.data email=form.email.data location=form.location.data biography=form.biography.data profile_photo=form.profile_photo.data filename=secure_filename(profile_photo.filename) profile_photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) user=Users(username=username,password=password,firstname=firstname,lastname=lastname,email=email,location=location,biography=biography,profile_photo=filename,joined_on=format_date_joined()) db.session.add(user) db.session.commit() flash('Profile was successfully added','success') return redirect(url_for('home')) else: return render_template('profile.html',form=form)
def profile(username): form = ProfileForm() if form.is_submitted(): education = sanitizeStr(form.education.data) employment = sanitizeStr(form.employment.data) music = sanitizeStr(form.movie.data) movie = sanitizeStr(form.movie.data) nationality = sanitizeStr(form.nationality.data) birthday = form.birthday.data query_db( 'UPDATE Users SET education=?, employment=?, music=?, movie=?, nationality=?, birthday=? WHERE username=?', education, employment, music, movie, nationality, birthday, username) return redirect(url_for('profile', username=current_user.username)) user = query_db('SELECT * FROM Users WHERE username=?', username, one=True) return render_template('profile.html', title='profile', username=username, user=user, form=form)
def profile(): newProfileForm = ProfileForm() if request.method == "POST": if newProfileForm.validate_on_submit(): try: firstname = newProfileForm.firstname.data lastname = newProfileForm.lastname.data gender = newProfileForm.gender.data email = newProfileForm.email.data location = newProfileForm.location.data bio = newProfileForm.bibliography.data created = str(datetime.datetime.now()).split()[0] photo = newProfileForm.profilepic.data photo_name = secure_filename(photo.filename) user = UserProfile(firstname, lastname, gender, email, location, bio, created, photo_name) db.session.add(user) db.session.commit() photo.save( os.path.join(app.config['UPLOAD_FOLDER'], photo_name)) flash("Profile Added", "success") return redirect(url_for("profiles")) except Exception as e: db.session.rollback() print(e) flash("Internal Error", "danger") return render_template("profile.html", form=newProfileForm) errors = form_errors(newProfileForm) flash(''.join(error + " " for error in errors), "danger") return render_template("profile.html", form=newProfileForm)
def setprofile(p_id): #simple security fix if int(p_id) != current_user.id: return redirect(url_for('index')) form = ProfileForm( ) #----------------------------Bug is there-------------------------------------# user_id = current_user.id cur_user = Profile.query.filter(Profile.id == user_id).first() if form.validate_on_submit and request.method == 'POST': pr_obj = Profile.query.filter(Profile.id == current_user.id).first() if form.first_name.data is not None: pr_obj.first_name = form.first_name.data if form.last_name.data is not None: pr_obj.last_name = form.last_name.data if form.about_me.data is not None: pr_obj.about_me = form.about_me.data if form.phno.data is not None: pr_obj.phno = form.phno.data if form.qual.data is not None: pr_obj.qualification = form.qual.data if form.address.data is not None: pr_obj.address = form.address.data if form.experiance.data is not None: pr_obj.experiance = form.experiance.data if form.education.data is not None: pr_obj.education = form.education.data db.session.commit() return redirect(url_for('index')) return render_template('edit_profile.html', form=form, cur_user=cur_user)
def profile_form_submit(user_id): print('hey its the user_id', user_id) form = ProfileForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): profile = Profile.query.filter_by(user_id=user_id).first() if profile: profile.bio=form.data['bio'], profile.name=form.data['name'], profile.location=form.data['location'], profile.website = form.data['website'] else: profile = Profile( bio=form.data['bio'], name=form.data['name'], location=form.data['location'], website=form.data['website'], user_id=user_id ) db.session.add(profile) db.session.commit() return profile.to_dict()
def post(self): form = ProfileForm(request.form) if form.validate(): account = session_util.get_account() data = {field.name: field.data for field in form} del data['csrf_token'] del data['submit'] if not account.profile: account.profile = Profile(**data) else: account.profile.update(**data) account.profile.save() account.save() if account.team: team_util.validate_division(account.team) flash('Profile updated') return self.render_template(form=form)
def profile(): form = ProfileForm() if request.method == "POST" and form.validate_on_submit(): firstname = form.firstname.data lastname = form.lastname.data gender = form.gender.data email = form.email.data location = form.location.data biography = form.biography.data created_on = str(datetime.datetime.now()).split()[0] photo = form.fileupload.data photo_name = secure_filename(photo.filename) user = User(firstname, lastname, gender, email, location, biography, created_on, photo_name) db.session.add(user) db.session.commit() photo.save(os.path.join(app.config['UPLOAD_FOLDER'],photo_name)) flash("Profile Added", "success") return redirect(url_for("profiles")) return render_template('profile.html', form=form)
def newProfile(): form = ProfileForm() if request.method == 'GET': return render_template('newProfile.html', form=form) elif request.method == 'POST': if form.validate_on_submit(): firstname = form.firstname.data lastname = form.lastname.data gender = form.gender.data email = form.email.data location = form.location.data bio = form.bio.data dateCreated = datetime.date.today() photo = form.photo.data filename = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) userid = generateUserId(firstname, lastname) newUser = UserProfile(userid=userid, first_name=firstname, last_name=lastname, gender=gender, email=email, location=location, biography=bio, pic=filename, created_on=dateCreated) db.session.add(newUser) db.session.commit() flash("Profile Successfully Created", "success") return redirect(url_for('profiles'))
def profile(): myForm = ProfileForm() print(myForm) if request.method == 'POST' : if myForm.validate_on_submit(): first_name = myForm.firstname.data last_name = myForm.lastname.data location = myForm.location.data email = myForm.email.data biography = myForm.biography.data gender = myForm.gender.data file = myForm.photo.data name, ext = os.path.splitext(secure_filename(file.filename)) filename = hashlib.sha256(file.read()).hexdigest() + ext file.seek(0) file.save(os.path.join(app.instance_path, app.config['UPLOAD_FOLDER'], filename)) user = UserProfile(first_name,last_name,gender,email,location,biography,filename) db.session.add(user) db.session.commit() render_template('home.html') return render_template('profileForm.html',form=myForm)
def profile(username): form = ProfileForm() owner = True if username != current_user.username: owner = False user = User.query.filter_by(username = username).first() if not user: return error() if username == current_user.username and form.is_submitted(): user.education = form.education.data user.employment = form.employment.data user.music = form.music.data user.movie = form.movie.data user.nationality = form.nationality.data user.birthday = form.birthday.data db.session.add(user) db.session.commit() return redirect(url_for('profile', username=username)) return render_template('profile.html', title='profile', username=username, user=user, form=form, owner=owner)
def get(self, request): form = ProfileForm(initial={ "prefecture_id": request.user.person.prefecture_id, }) protocol = "https" if self.request.is_secure() else "http" current_site = get_current_site(self.request) domain = current_site.domain redirect_uri = protocol + "://" + domain + "/wca/authorization/?type=profile" notification = self.request.session.get("notification") if self.request.session.get("notification") is not None: del self.request.session["notification"] context = { "form": form, "wca_oauth_authorization": settings.WCA_OAUTH_AUTHORIZATION, "wca_client_id": settings.WCA_CLIENT_ID, "stripe_oauth_authorization": settings.STRIPE_OAUTH_AUTHORIZATION, "stripe_client_id": settings.STRIPE_CLIENT_ID, "redirect_uri": redirect_uri, "notification": notification, } return render(request, "app/scj/profile.html", context)