def addProfile(): #Adds new user profile form= UserProfile() if request== "POST": if form.validate_on_submit: userid= str(uuid.uuid4()) firstname= request.form['firstname'] lastname=request.form['lastname'] username=request.form['username'] age=request.form['age'] biography=request.form['biography'] gender= request.form["gender"] image=request.form['image'] file_folder= app.config['UPLOAD_FOLDER'] filename= secure_filename(image.filename) image.save(os.path.join(file_folder, filename)) created_on = time.strftime("%a %d %B %Y") user= UserProfile(userid=userid,firstname=firstname,lastname=lastname,age=age,biography=biography,username=username) db.session.add(user) db.session.commit() flash("New user created") return render_template('newprofile.html')
def profile(): form = ProfileForm() if request.method == 'POST': if form.validate_on_submit(): firstname = form.firstname.data lastname = form.lastname.data location = form.location.data email = form.email.data biography = form.biography.data gender = form.gender.data #form.photo.label.text = 'Browse...' photo = form.photo.data filename = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) date_created = datetime.datetime.now().strftime("%B %d, %Y") new_user = UserProfile(firstname=firstname, lastname=lastname, biography=biography, photo=filename, gender=gender, location=location, created_on=date_created, email=email) db.session.add(new_user) db.session.commit() flash('Profile added', 'success') return redirect(url_for("profiles")) return render_template('profile.html', form=form)
def profile(): profile = UserProfile.query.filter_by(user_id=current_user.id).first() form = ProfileForm(obj=profile) if form.validate_on_submit(): if profile: form.populate_obj(profile) db.session.commit() flash('Profile Information has been saved!') return redirect(url_for('account')) new_profile = UserProfile(user_id=current_user.id, first_name=form.first_name.data, last_name=form.last_name.data, birth_date=form.birth_date.data, address_1=form.address_1.data, address_2=form.address_2.data, city=form.city.data, state=form.state.data, zip=form.zip.data) db.session.add(new_profile) db.session.commit() flash('Profile Information has been saved!') return redirect(url_for('account')) return render_template('profile.html', form=form)
def profile(): """Render the website's profile page""" form = ProfileForm() us_Id = 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 = format_date(get_date()) image = form.image.data imageName = first_name + last_name + str(us_Id + 1) newUser = 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(newUser) db.session.commit() 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 profile(): profileForm = ProfileForm() if request.method == "POST": if profileForm.validate_on_submit(): profilepic = profileForm.profilePic.data filename = secure_filename(profilepic.filename) profilepic.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) firstName = profileForm.firstName.data lastName = profileForm.lastName.data gen = profileForm.gender.data email = profileForm.email.data loc = profileForm.location.data bio = profileForm.biography.data date_joined = format_date_joined() user = UserProfile(firstName, lastName, gen, email, loc, bio, filename, date_joined) db.session.add(user) db.session.commit() flash('Profile was created successfully', 'success') return redirect(url_for('profiles')) else: flash(flash_errors(profileForm)) return render_template('profile.html', form=profileForm)
def submit(): form = ProfileForm() # if form.validate_on_submit(): if request.method == 'POST': req = request.form file = request.files.get('photo') filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) new_profile = UserProfile(firstname=req.get('firstName'), lastname=req.get('lastName'), email=req.get('email'), bio=req.get('biography'), location=req.get('location'), photo=file.filename, gender=req.get('gender'), photo_data=file.read()) db.session.add(new_profile) db.session.commit() return redirect(url_for('profiles')) else: return redirect(url_for('profile'))
def add_profile(): """GET provides the profile form while POST stores profile""" profileform = ProfileForm() if request.method == 'POST' and profileform.validate_on_submit(): # Get values from form fname = request.form['first_name'] lname = request.form['last_name'] gender = request.form['gender'] email = request.form['email'] location = request.form['location'] bio = request.form['bio'] file = profileform.photo.data filename = secure_filename(file.filename) file.save(os.path.join(path, filename)) try: profile = UserProfile(fname, lname, gender, email, location, bio, filename) db.session.add(profile) db.session.commit() flash('Profile Saved', 'success') return redirect(url_for('view_profiles')) except: flash("Profile failed to save", 'danger') return render_template('add_profile.html', form=profileform)
def addProperty(): form= UserForm() if request.method == "POST": if form.validate_on_submit() == True: #Gets the user input from the form proptitle = form.propertytitle.data description = form.description.data noofrooms = form.noofrooms.data noofbathrooms = form.noofbathrooms.data price = form.price.data proptype = form.propertytype.data location = form.location.data filename = uploadPhoto(form.property_picture.data) #create user object and add to database user = UserProfile(proptitle,description,noofrooms,noofbathrooms,price,proptype, location, filename) db.session.add(user) db.session.commit() # remember to flash a message to the user flash('Property information uploaded successfully.', 'success') else: flash('Property information not uploaded', 'danger') return redirect(url_for("properties")) # they should be redirected to a secure-page route instead return render_template("addproperty.html", form=form)
def profile(): addprofile = addProfile() if request.method == 'POST': if addprofile.validate_on_submit(): fname = addprofile.fname.data lname = addprofile.lname.data gender = addprofile.gender.data email = addprofile.email.data location = addprofile.location.data bio = addprofile.bio.data date = datetime.datetime.now() created_on = date.strftime("%B %d, %Y") photo = addprofile.photo.data filename = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) user = UserProfile(first_name=fname, last_name=lname, gender=gender, email=email, location=location, bio=bio, photo=filename, created_on=created_on) db.session.add(user) db.session.commit() flash('File Uploaded', 'success') return redirect(url_for('profiles')) flash_errors(addprofile) return render_template('profile.html', form=addprofile)
def add_profile(): """Either (GET) provide profile form or (POST) create the profile""" form = ProfileForm() if form.validate_on_submit(): # Get values from form fname = request.form['first_name'] lname = request.form['last_name'] gender = request.form['gender'] email = request.form['email'] location = request.form['location'] bio = request.form['bio'] try: """Idea for now: need to save the picture, and save the filename. Store items to database""" p_filename = save_photo( request.files['profile_picture']) # profile photo filename profile = UserProfile(fname, lname, gender, email, location, bio, p_filename) db.session.add(profile) db.session.commit() flash('User successfully created', 'success') return redirect(url_for('view_profiles')) except: flash("User could not be created", 'danger') return render_template('add_profile.html', form=form)
def profile(): form = ProfileForm() if request.method == "POST" and form.validate_on_submit(): # fname = form.fname.data # lname = form.lname.data # email = form.email.data # location = form.location.data # gender = form.gender.data # biography = form.biography.data file = form.image.data filename = secure_filename(file.filename) file.save(os.path.join(path, filename)) user = UserProfile( request.form['fname'], request.form['lname'], request.form['email'], request.form['location'], request.form['gender'], request.form['bio'], filename, # datetime.datetime.now() datetime.datetime.now().strftime("%B %d, %Y")) db.session.add(user) db.session.commit() flash('Profile Saved', 'success') return redirect(url_for("profiles")) return render_template("profile.html", form=form)
def create_profile(current_user): if request.content_type == 'application/json': data = request.get_json() emp_id = current_user.id first_name = data.get('first_name') last_name = data.get('last_name') designation = data.get('designation') experience = data.get('experience') gender = data.get('gender') skills = data.get('skills') client = data.get('client') location = data.get('location') address = data.get('address') mobile = data.get('mobile') image_url = data.get('image_url') linked_in = data.get('linked_in') github = data.get('github') slack = data.get('slack') joining_date = data.get('joining_date') dob = data.get('dob') if emp_id: user_profile = UserProfile(emp_id, first_name, last_name, designation, experience, gender, skills, client, location, address, mobile, image_url, linked_in, github, slack, joining_date, dob) else: return {"message": "unprocessible entity"}, 422 try: user_profile.save() return { "message": "Profile added successfully" }, 200 except: return {"message": "unable to add profile"}, 500
def profile(): form = profileForm() if request.method == "POST" and form.validate_on_submit(): #collect from data fname = form.firstName.data lname = form.lastName.data gender = form.gender.data email = form.email.data location = form.location.data bio = form.biography.data date_joined = datetime.now().strftime("%B %d, %Y") img = form.photo.data filename = secure_filename(img.filename) #set custom file name for reference if filename.endswith('.' + "png"): photo_name = "pic_" + fname + "_" + email + ".png" elif filename.endswith('.' + "jpg"): photo_name = "pic_" + fname + "_" + email + ".jpg" img.save(os.path.join(app.config['UPLOAD_FOLDER'], photo_name)) #connect to database and save data user_profile = UserProfile(fname, lname, gender, email, location, bio, date_joined, photo_name) db.session.add(user_profile) db.session.commit() flash("Your profile has been sucessfully added!", "success") return redirect(url_for('profiles')) return render_template('add_profile.html', form=form)
def add_profile(): id_strt = random.randint(0, 99999) prifile_pic_folder = 'app/static/pics' if request.method == 'POST': userid = id_strt firstname = request.form['firstname'] lastname = request.form['lastname'] age = request.form['age'] sex = request.form['sex'] bio = request.form['bio'] created_on = timeinfo() profile_pic = request.form['profile_pic'] username = request.form['username'] # save pic to pics file filename = secure_filename(profile_pic.filename) profile_pic.save(os.path.join(prifile_pic_folder, filename)) user = UserProfile(userid, firstname, lastname, username, age, bio, created_on, profile_pic) db.session.add(user) db.session.commit() flash('Success!!!') return render_template('profile.html')
def profile(): file_folder = app.config['UPLOAD_FOLDER'] if request.method == 'POST': first_name = request.form['first_name'] last_name = request.form['last_name'] username = request.form['username'] age = request.form['age'] biography = request.form['biography'] file = request.files['file'] filename = secure_filename(file.filename) file.save(os.path.join(file_folder, filename)) gender = request.form['gender'] date = time.strftime("%Y/%b/%d") userid = str(uuid.uuid4().fields[-1])[:8] flash('profile saved') user = UserProfile(id=userid, date=date, first_name=first_name, last_name=last_name, username=username, age=age, biography=biography, gender=gender, image=file.filename) db.session.add(user) db.session.commit() return redirect(url_for('home')) """Render the website's profile page.""" return render_template('profile.html')
def profile(): form = ProfileForm() if request.method == 'POST': if form.validate_on_submit(): firstname = form.firstname.data lastname = form.lastname.data email = form.email.data biography = form.biography.data location = form.location.data gender = form.gender.data created_on = format_date_joined() photo = form.photo.data filename = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) User = UserProfile(firstname=firstname, lastname=lastname, email=email, location=location, gender=gender, created_on=created_on, filename=filename, biography=biography) db.session.add(User) db.session.commit() flash("User Created Successfully!") return redirect(url_for("viewprofiles")) else: flash_errors(form) return render_template('profile.html', form=form)
def profile(): form = ProfileForm() if request.method == "POST" and form.validate_on_submit(): profilePhoto = form.photo.data filename = secure_filename(profilePhoto.filename) profilePhoto.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) newUser = UserProfile( # first_name = form.first_name.data, # last_name = form.last_name.data, # email = form.email.data, # location = form.location.data, # gender = form.gender.data, # biography = form.biography.data, # profilePhoto = filename, request.form['first_name'], request.form['last_name'], request.form['email'], request.form['location'], request.form['gender'], request.form['biography'], filename, created_on=datetime.now().strftime("%B %d, %Y")) db.session.add(newUser) db.session.commit() flash('You have successfully added a new profile.', 'success') return redirect(url_for('profiles')) return render_template('profile.html', form=form)
def profile(): form = MyForm() if request.method == "POST": file_folder = app.config['UPLOAD_FOLDER'] if form.validate_on_submit(): fname = request.form['fname'] lname = request.form['lname'] username = request.form['username'] age = request.form['age'] biography = request.form['biography'] gender = request.form['gender'] image = request.files['image'] imagename = secure_filename(image.filename) image.save(os.path.join(file_folder, imagename)) userid = randint(100000, 999999) created_on = datetime.date.today() new_profile = UserProfile(userid, fname, lname, username, age, gender, biography, imagename, created_on) db.session.add(new_profile) db.session.commit() flash("Created Successfully", "success") return redirect(url_for("profile")) """Render the website's profile_form page.""" return render_template('profile_form.html', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('investments.dashboard', username=current_user.username)) form = RegistrationForm() if form.validate_on_submit(): email = form.email.data username = form.username.data # date_of_birth = form.date_of_birth.data or None date_of_birth = None first_name = form.first_name.data last_name = form.last_name.data or None password = form.password.data user = UserProfile(username=username, email=email, first_name=first_name, password=password, last_name=last_name, date_of_birth=date_of_birth) db.session.add(user) db.session.commit() token = user.get_reset_password_token() send_email('Activate your account', sender=current_app.config['ADMINS'][0], recipients=[user.email], text_body=render_template('account_activate.txt', user=user, token=token), html_body=render_template('account_activate_email_format.html', user=user, token=token)) flash('Thanks for registering with us!Please check you mail for activating you account.') return redirect(url_for('accounts.login')) else: print(form.errors) return render_template('register.html', form=form)
def register(): """ Renders user registration page""" 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 location = form.location.data email = form.email.data biography = form.biography.data photo = form.profile_photo.data filename = secure_filename(photo.filename) #photo.save(os.path.join(app.config['UPLOAD_FOLDER'],filename)) photo.save( os.path.join("./app", app.config['PROFILE_IMG_UPLOAD_FOLDER'], filename)) date_created = datetime.datetime.now().strftime("%B %d, %Y") new_user = UserProfile(username=username, password=password, firstname=firstname, lastname=lastname, biography=biography, profile_photo=filename, location=location, joined_on=date_created, email=email) db.session.add(new_user) db.session.commit() return jsonify(message="User successfully registered")
def addprofile(): form = ProfileForm() filefolder = app.config["UPLOAD_FOLDER"] file = request.files['picture'] filename = secure_filename(file.filename) file.save(os.path.join(filefolder, filename)) flash('File uploaded') img = "./static/uploads/" + filename date = str(datetime.date.today()) username = form.username.data firstname = form.firstname.data lastname = form.lastname.data gender = form.gender.data age = form.age.data bio = form.bio.data password = form.password.data user = UserProfile(first_name=firstname, last_name=lastname, username=username, password=password, age=age, bio=bio, img=img, date=date, gender=gender) db.session.add(user) db.session.commit() return render_template(url_for('profiles'))
def profile(): myform = SignupForm() if request.method == "POST": if myform.validate_on_submit(): first = myform.firstname.data last = myform.lastname.data gen = myform.gender.data email = myform.email.data loc = myform.location.data bio = myform.biography.data pic = request.files['file'] now = datetime.now() signdate = now.strftime("%B") + " " + str(now.day) + ", " + str( now.year) photoname = secure_filename(pic.filename) pic.save(os.path.join(app.config['UPLOAD_FOLDER'], photoname)) user = UserProfile(first, last, gen, email, loc, bio, signdate, photoname) db.session.add(user) db.session.commit() flash("Profile Successfully Created", "success") return redirect("/") else: flash("Failed to create profile", "danger") return render_template('profile.html', myform=myform)
def profile(): form = ProfileForm() if request.method == 'POST': print(form) #if form.validate_on_submit(): if True: firstname = form.firstname.data lastname = form.lastname.data gender = form.gender.data email = form.email.data location = form.location.data bio = form.bio.data image = form.image.data filename = secure_filename(image.filename) image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) user = UserProfile(firstname, lastname, gender, email, location, bio, filename) db.session.add(user) db.session.commit() flash('Your profile was sucessfully created!') return redirect('/profiles') flash_errors(form) return render_template('profile_form.html', form=form)
def CreatePlayer(self): username = self.POST.get('username') phone = self.POST.get('phone') time = self.POST.get('time') area = self.POST.get('area') school = self.POST.get('school') where = self.POST.get('where') nowtime = datetime.datetime.now() age = int(nowtime.strftime('%Y')) - int(time[:4]) user = User.objects.filter(username=phone) try: if len(user) == 0: user = User.objects.create_user(username=phone, password='******') profile = UserProfile() profile.user_id = user.id profile.name = username profile.palace = area profile.role = '球员' profile.rights = 4 profile.date = time profile.age = age profile.school = school profile.save() player_basic = Player_Basic() player_basic.user_id = profile.id player_basic.position = where player_basic.where_from = self.user.id player_basic.save() return JsonResponse(Msg().Success(msg='添加成功'), safe=False) else: return JsonResponse(Msg().Success(msg='该手机号已被注册了'), safe=False) except Exception as e: print(e) return JsonResponse(Msg().Error(), safe=False)
def profile(): form1 = ProfileForm() form2 = PasswordForm() user = User.query.filter_by(UserAccountId=current_user.get_id()).first() if form1.submit.data and form1.validate_on_submit(): if user.Profile == None: user_profile = UserProfile(FirstName=form1.first_name.data, LastName=form1.last_name.data, DOB=form1.dob.data, \ Phone=form1.phone.data, Address=form1.address.data, Country=form1.country.data, owner=user) db.session.add(user_profile) db.session.commit() else: user.Profile.FirstName = form1.first_name.data user.Profile.LastName = form1.last_name.data user.Profile.DOB = form1.dob.data user.Profile.Phone = form1.phone.data user.Profile.Address = form1.address.data user.Profile.Country = form1.country.data db.session.commit() flash('Changes succesfully saved!') return redirect(url_for('profile')) if form2.update.data and form2.validate_on_submit(): if user is None or not user.check_password(form2.password.data): flash('Invalid current password') return redirect(url_for('profile')) user.set_password(form2.new_password.data) db.session.commit() flash('Password succesfully updated!') return redirect(url_for('profile')) return render_template('account-profile.html', title='Profile', form1=form1, form2=form2)
def CreateRole(self): username = self.POST.get('username') phone = self.POST.get('phone') time = self.POST.get('time') area = self.POST.get('area') school = self.POST.get('school') role = self.POST.get('role') nowtime = datetime.datetime.now() age = int(nowtime.strftime("%Y")) - int(time[:4]) user = User.objects.filter(username=phone) team_id = UserProfile.objects.get(user_id=self.user.id).team_id try: if len(user) == 0: user = User.objects.create_user(username=phone, password='******') profile = UserProfile() profile.user_id = user.id profile.name = username profile.palace = area if role == '教练': profile.rights = 2 else: profile.rights = 3 profile.role = role profile.date = time profile.age = age profile.school = school profile.team_id = team_id profile.save() return JsonResponse(Msg().Success(msg='添加成功)'), safe=False) else: return JsonResponse(Msg().Success(msg='该手机号码已被注册'), safa=False) except Exception as e: print(e) return JsonResponse(Msg().Error(), safe=False)
def profile(): form = ProfileForm() if request.method == "POST" and form.validate_on_submit(): #userid = str first_name = request.form.data['first_name'] last_name = request.form.data['last_name'] gender = request.form.data['gender'] email = request.form.data['email'] location = request.form.data['location'] biography = request.form.data['biography'] created_on = time.strftime('%Y/%b/%d') photo = request.files.data['file'] if photo: filename = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD FOLDER'], filename)) user = UserProfile(first_name='first_name', last_name='last_name', gender='gender', email='email', location='location', biography='biography', photo='photo', created_on='created_on') db.session.add(user) db.session.commit() return render_template('profile.html', form=form)
def register_user(): payload = request.get_json() name, email = payload['name'], payload['email'] password = bcrypt.generate_password_hash( payload['password']).decode('utf8') added_user = User(name, email, password) profile_added = UserProfile() added_user.profile.append(profile_added) try: db.session.add(added_user) db.session.commit() except exc.IntegrityError: db.session().rollback() raise BadRequest("Invalid: the username or email already exist!") confirmation_token = generate_confirmation_token(added_user.id, added_user.email) global token_whitelist token_whitelist[confirmation_token] = 1 send_confirmation_email(added_user.email, confirmation_token) return jsonify( message= 'Thanks for registering! Please check your email to confirm your email address.', added_user=added_user.serialize)
def login(): form = LoginForm() if request.method == "POST" and form.validate_on_submit(): username = form.username.data password = form.password.data userlog=get_user(username) if userlog: user = UserProfile(userlog['Username'],userlog['Password']) if user is not None and check_password_hash(user.password, password): remember_me = False # get user id, load into session login_user(user,remember_me) flash('Login successful.', 'success') print('login sucessfull',user.password) session['USERNAME'] = user.username return redirect(url_for('profile')) else: flash('username or Password is incorrect.', 'danger') else: flash('Username or password is incorrect.', 'danger') return render_template("login.html", form=form)
def register(): form = RegistrationForm() if request.method == 'POST' and form.validate_on_submit(): username = form.username.data password = form.password.data #password is already hashed in the models.py...consider removing the line below #password=generate_password_hash(password, method='pbkdf2:sha256', salt_length=8) firstname = form.firstname.data lastname = form.lastname.data email = form.email.data location = form.location.data biography = form.biography.data profile_picture = form.profile_picture.data filename = secure_filename(profile_picture.filename) profile_picture.save( os.path.join(app.config['UPLOAD_FOLDER'], filename)) joined = format_date_joined() user = UserProfile(username, password, firstname, lastname, email, location, biography, filename, joined) db.session.add(user) db.session.commit() return jsonify({"message": "User successfully registered"}), 201 return make_response(jsonify(error=form_errors(form)), 400)