def addprofile(): userform = CreateUserForm() if request.method == 'POST': if userform.validate_on_submit(): firstname = userform.firstname.data lastname = userform.lastname.data email = userform.email.data biography = userform.biography.data location = userform.location.data sex = userform.gender.data created_on = format_date_joined() photo = userform.photo.data filename = photo.filename photo.save(os.path.join(app.config['UPLOAD_FOLDER'],filename)) newUser=UserProfile(first_name=firstname,last_name=lastname,email=email,location=location,sex=sex,created_on=created_on,filename=filename) UserProfile() db.session.commit() flash("User Created") return render_template("home.html",sex=sex,firstname=firstname,lastname=lastname,email=email,biography=biography,location=location,filename=filename) else: flash_errors(userform) return render_template('profile.html',form=userform)
def register(request): #current_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()); if request.method == 'POST': registerform = RegisterForm(request.POST) if registerform.is_valid(): registerinfo = registerform.cleaned_data username = registerinfo['username'] password = registerinfo['password1'] email = registerinfo['email'] phone = registerinfo['phone'] #avatar = registerinfo['avatar'] #destination = open(avatar.name, 'wb+') #for chunk in avatar.chunks(): # destination.write(chunk) #destination.close() new_user = User(username=username, email=email) new_user.set_password(password) new_user.save() if request.FILES: avatar = request.FILES['avatar'] avatar.name = str(new_user.id) + '.' + avatar.name.split('.')[1] profile = UserProfile(phone=phone,avatar=avatar,user=new_user) else: profile = UserProfile(phone=phone,user=new_user) #why cant profile = UserProfile.objects.create(phone=phone,user=new_user) profile.save() return HttpResponseRedirect('/polls/') else: registerform = RegisterForm() return render(request,'polls/register.html', {'registerform':registerform})
def test_user_profiles(self): alice = User.objects.create_user('alice', '*****@*****.**') bob = User.objects.db_manager('other').create_user('bob', '*****@*****.**') alice_profile = UserProfile(user=alice, flavor='chocolate') alice_profile.save() bob_profile = UserProfile(user=bob, flavor='crunchy frog') bob_profile.save() self.assertEqual(alice.get_profile().flavor, 'chocolate') self.assertEqual(bob.get_profile().flavor, 'crunchy frog')
def profile(): newProfileForm = NewProfileForm() if request.method == "POST" and newProfileForm.validate_on_submit(): firstname = newProfileForm.firstname.data lastname = newProfileForm.lastname.data gender = newProfileForm.gender.data email = newProfileForm.email.data location = newProfileForm.location.data bio = newProfileForm.bio.data created_on = format_date_joined() photo = newProfileForm.photo.data image = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], image)) user = UserProfile(first_name=firstname, last_name=lastname, gender=gender, email=email, location=location, bio=bio, image=image, created_on=created_on) db.session.add(user) db.session.commit() flash("Profile was successfully added", "success") return redirect(url_for("profiles")) flash_errors(newProfileForm) return render_template("profile.html", newProfileForm=newProfileForm)
def my_account(request): user_data = { 'first_name': request.user.first_name, 'last_name': request.user.last_name, 'email': request.user.email } try: profile_obj = request.user.get_profile() except ObjectDoesNotExist: profile_obj = UserProfile(user=request.user, acct_type=1) if request.method == 'POST': user_form = UserForm(request.POST, instance=request.user) profile_form = ProfileForm(request.POST, instance=profile_obj) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() return HttpResponseRedirect('/') else: user_form = UserForm(initial=user_data) profile_form = ProfileForm(initial=get_profile_data(profile_obj)) context = { 'title': labels['profile'], 'username': request.user.username, 'user_form': user_form, 'profile_form': profile_form, } # Return response t = get_template('my_account.html') html = t.render(RequestContext(request, context)) return HttpResponse(html)
def register(self, request, form_class): new_user = super(MyRegistrationView, self).register(request, form_class) user_profile = UserProfile() user_profile.user = new_user user_profile.field = form_class.cleaned_data['field'] user_profile.save() return user_profile
def get_or_create_weibo_user(client, code): res = client.request_access_token(code) # print "token:", str(res.access_token), "expires: ", res.expires_in token = res.access_token expires_in = res.expires_in client.set_access_token(token, expires_in) # first, try to get user from the mcache user = cache.get(str(token)) if user: print "get_or_create_weibo_user, from cache: %s %d" % (str(user), user.id) #try: # mcache_set(str(user.id), user) # return user #except DetachedInstanceError: # print "merge user ...." # user = db.session.merge(user) # mcache_set(str(user.id), user) # return user user = db.session.merge(user) print "get_or_create_weibo_user, cache db merge: %s %d" % (str(user), user.id) return user auth_id = "weibo_" + str(res.uid) user = User.query.get_by_authid(auth_id) if not user: weibo_user = client.get.users__show(uid=res.uid) print "get_or_create_weibo_user", weibo_user kw = dict() kw['auth_id'] = auth_id kw['nickname'] = kw['username'] = weibo_user.screen_name kw['avater'] = weibo_user.profile_image_url kw['gender'] = weibo_user.gender kw2 = dict() kw2['province'] = weibo_user.province kw2['city'] = weibo_user.city kw2['copper_coins'] = 5000 #print kw, kw2 user = User(**kw) profile = UserProfile(**kw2) user.profile = profile db.session.add_all([user, profile]) db.session.commit() # save user in mcache #mcache_set(str(token), user, expires_in=expires_in-int(time.time())) #mcache_set(str(user.id), user) cache.set(str(token), user, expires_in=expires_in - int(time.time())) cache.set(str(user.id), user) print "get_or_create_weibo_user, from db: %s %d. set token: %s" % ( str(user), user.id, str(token)) return user
def profile(): """Render the website's profile page.""" file_folder = 'app/static/uploads' filename='no file' if request.method == 'POST': uid=620000000+randint(10000,99999) creation =datetime.now() fname=request.form.get('fname') lname=request.form.get('lname') bio=request.form.get('bio') file = request.files['profile_image'] filename = secure_filename(file.filename) file.save(os.path.join(file_folder, filename)) profile_image=filename age=request.form.get('age') gender=request.form.get('gender') user =UserProfile(id=uid,profile_creation=creation,first_name=fname, last_name=lname,bio=bio,imagename=profile_image,age=age,gender=gender) db.session.add(user) db.session.commit() flash("Information accepted") return redirect(url_for('home')) return render_template('profile.html')
def post(self): """ """ new_profile = self.current_userprofile.to_python() # Apply each argument we accept to the new structure new_profile['name'] = self.get_argument('name', None) new_profile['bio'] = self.get_argument('bio', None) new_profile['location_text'] = self.get_argument('location_text', None) new_profile['avatar_url'] = self.get_argument('avatar_url', None) new_profile['email'] = self.get_argument('email', None) # Help a user out if they didn't put the "http" in front website = self.get_argument('website', None) if not website.startswith('http'): website = 'http://%s' % (website) new_profile['website'] = website # Save values if they pass validation try: new_up = UserProfile(**new_profile) new_up.validate() save_userprofile(self.db_conn, new_up) self._current_userprofile = new_up except Exception, e: # TODO handle errors nicely raise
def profile(): form=AddProfile() if request.method=="POST": username = request.form ['username'] id = random.randint(1000, 1099) firstname = request.form['firstname'] lastname = request.form['lastname'] age = request.form['age'] biography = request.form['biography'] gender = request.form['gender'] file = request.files['image'] image = secure_filename(file.filename) file.save(os.path.join("app/static/images", image)) password = request.form['password'] datejoined= datetime.now().strftime("%a, %d %b %Y") profile = UserProfile (id, username, firstname, lastname, password, age, biography, gender, image, datejoined) db.session.add(profile) db.session.commit() flash ('User ' + username + ' sucessfully added!', 'success') flash ('Please proceed to "Login"', 'success') return redirect (url_for('profile')) flash_errors(form) return render_template('profile.html', form=form)
def profile_view(request): profile = UserProfile.objects.get(username=request.user.username) if profile == None: profile = UserProfile(username=request.user.username) profile.level = 'normal' pcs = UserProfile.objects.filter(level='pc').all() if request.method == 'POST': profile.name = request.POST.get('name', '') profile.affiliation = request.POST.get('affiliation', '') profile.acm_number = request.POST.get('acm_number', '') profile.email = request.POST.get('email', '') profile.save() UserPCConflict.objects.filter(user=profile).delete() pc_conflicts = [] for conf in request.POST.getlist('pc_conflicts[]'): new_pc_conflict = UserProfile.objects.get(username=conf) UserPCConflict.objects.create(user=profile, pc=new_pc_conflict) pc_conflicts.append(new_pc_conflict) else: pc_conflicts = [uppc.pc for uppc in UserPCConflict.objects.filter(user=profile).all()] return ("profile.html", { "name": profile.name, "affiliation": profile.affiliation, "acm_number": profile.acm_number, "pc_conflicts": pc_conflicts, "email": profile.email, "pcs": pcs, "which_page": "profile", "pcs": [{'pc':pc, 'conflict':pc in pc_conflicts} for pc in pcs], })
def profile(): """Render the website's about page.""" if request.method == 'POST': file_folder = app.config['UPLOAD_FOLDER'] firstname = request.form['f_name'] image = request.files['file'] filename = secure_filename(image.filename) image.save(os.path.join(file_folder, filename)) extension = list(image)[-1:-4] print image lastname = request.form['l_name'] username = request.form['u_name'] userid = "6200" + str(random.randint(1, 400)) age = request.form['age'] bio = request.form['biography'] gender = request.form['gender_types'] now = date.today() user = UserProfile(pic_ex=extension, userid=userid, first_name=firstname, last_name=lastname, username=username, age=age, biography=bio, created_on=now.strftime('%d, %m , %Y'), gender=gender) db.session.add(user) db.session.commit() flash('Your information has been saved to the Database') return redirect(url_for('home')) return render_template('profile.html')
def signup_display(request): #return render(request, 'signup.html', {'page_title': 'Sign Up', }) if request.method == 'POST': request_username = request.POST.get('username','') request_password = request.POST.get('password','') request_psw_confirm = request.POST.get('psw_confirm') request_email = request.POST.get('email') if request_password != request_psw_confirm: return render(request, 'signup.html', {'page_title': 'Sign Up', 'errors': '1' }) if User.objects.filter(username = request_username).exists() or User.objects.filter(email = request_email).exists(): return render(request, 'signup.html', {'page_title': 'Sign Up', 'errors': '2' }) new_user = User.objects.create_user(request_username, request_email, request_password) new_user.save() new_profile = UserProfile(user_account = new_user, username = new_user.username, avatar = 'http://lorempixel.com/60/60/') new_profile.save() new_user_session = auth.authenticate(username = request_username, password = request_password) auth.login(request, new_user_session) return HttpResponseRedirect(request.GET.get('continue', 'http://localhost/')) return render(request, 'signup.html', {'page_title': 'Sign Up', 'errors': '0'})
def profile(): """Render website's profile page.""" file_folder = app.config['UPLOAD_FOLDER'] proform = profileForm() if request.method == 'POST': # Accept profile details username = proform.username.data firstname = proform.firstname.data lastname = proform.lastname.data age = proform.age.data biography = proform.biography.data gender = proform.gender.data file = request.files['file'] filename = secure_filename(file.filename) path = "/static/Profilepics/" + filename file.save("./app" + path) file = path user = UserProfile(100, username, firstname, lastname, age, gender, biography, file, date()) db.session.add(user) db.session.commit() return redirect(url_for('profile')) else: flash('There was an error! lets try again', 'oops') return render_template('profile.html', form=proform)
def profile(): form = CreationForm() if form.validate() and request.method == "POST": user = UserProfile(first_name=request.form['first_name'], last_name=request.form['last_name'], email=request.form['email'], location=request.form['location'], photo=request.files['photo'].filename, bio=request.form['bio'], gender=request.form['gender'], datte=datetime.datetime.now().strftime("%B %d,%Y")) db.session.add(user) db.session.commit() file = request.files['photo'] filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) flash('You have successfully filled out the form', 'success') return render_template( "profile.html", first_name=request.form['first_name'], last_name=request.form['last_name'], email=request.form['email'], location=request.form['location'], photo=filename, bio=request.form['bio'], datte=datetime.datetime.now().strftime("%B %d,%Y")) return profiles("Please select a profile")
def login(request, errorcode=None): logout(request) storage = messages.get_messages(request) storage.used = True if request.method == 'POST': # login the user; return an error message if applicable if 'login' in request.POST: username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: auth_login(request, user) if request.user.is_authenticated(): return HttpResponseRedirect('/home') else: # Return a 'disabled account' error message return HttpResponseRedirect('/login/1/') else: # return an 'invalid login' error message return HttpResponseRedirect('/login/1/') # make a new account if 'create' in request.POST: username = request.POST['username'] try: User.objects.get(username=username) return HttpResponseRedirect('/login/2/') except: first_name = request.POST['firstname'] last_name = request.POST['lastname'] password = request.POST['password'] name = first_name + ' ' + last_name new_user = User.objects.create_user(username, '', password) new_user.save() new_user_profile = UserProfile(user=new_user, name=name) new_user_profile.save() user = authenticate(username=username, password=password) auth_login(request, user) return HttpResponseRedirect('/home') else: if errorcode == "1": loginerror = "Incorrect username or password." registererror = "" elif errorcode == "2": loginerror = "" registererror = "Username already taken. Please choose another one." else: loginerror = "" registererror = "" error = "" return render_to_response('login.html', { 'loginerror': loginerror, 'registererror': registererror, 'errorcode': errorcode }, context_instance=RequestContext(request))
def profile(): form = MyForm() print form.validate_on_submit() print form.errors print request.form if request.method == 'POST' and form.validate_on_submit(): count = db.session.query(UserProfile).count() location = form.location.data bio = form.biography.data lname = form.lastname.data fname = form.firstname.data mail = form.email.data gender = form.gender.data photograph = form.photo.data date = datetime.date.today() uid = 10000 + count filename = str(uid) + ".jpg" photograph.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) user = UserProfile(id=uid, first_name=fname, last_name=lname, gender=gender, location=location, bio=bio, email=mail, created_on=date) db.session.add(user) db.session.commit() flash('Profile created!', 'success') return redirect(url_for('profiles')) else: return render_template('profile.html', form=form)
def NewUser(request): if request.POST: form = NewUserForm(request.POST) if form.is_valid(): Name = form.cleaned_data['Name'] login = form.cleaned_data['login'] password = form.cleaned_data['password'] phone = form.cleaned_data['phone'] Birthday = form.cleaned_data['Birthday'] #Last_connection= form.clean_data['Last_connection'] email = form.cleaned_data['email'] FreshUser = User.objects.create_user(username=login, email=email, password=password) #FreshUser= users(Name=Name, login=login, password=password, phone=phone, Birthday=Birthday, email=email) #FreshUser= users(Name=Name, login=login, password=password, phone=phone, Birthday=Birthday, Last_connection=Last_connection, email=email) FreshUser.is_active = True #switch off to enable email verification #FreshUser.last_name=Name FreshUser.save() Fresh = UserProfile(user_auth=FreshUser, phone=phone, Birthday=Birthday) Fresh.save() #return HttpResponseRedirect(reverse('public_empty')) return HttpResponse("New User Added") else: return render(request, 'vine/NewUser.html', {'form': form}) else: form = NewUserForm() return render(request, 'vine/NewUser.html', {'form': form})
def Profile(): form = uploadForm() if request.method == "POST" and form.validate_on_submit(): dateCreated = datetime.datetime.now() fname = form.firstname.data lname = form.lastname.data gen = form.gender.data email = form.email.data location = form.location.data bio = form.bio.data pic = form.photo.data filename = secure_filename(pic.filename) user = UserProfile(first_name=fname, last_name=lname, gender=gen, email=email, location=location, bio=bio, img_name=filename, date_created=dateCreated) db.session.add(user) db.session.commit() pic.save(os.path.join(imgfolder, filename)) flash('Successfully added.', 'success') return redirect(url_for('Profiles')) return render_template('Profile.html', form=form)
def createuser(): form = CreateUserForm() error = None if (request.method == "POST"): if form.validate() == False: flash_errors(form) return redirect(url_for('createuser', error=error)) else: uid = random.randint(1, 1000) firstname = form.firstname.data lastname = form.lastname.data gender = form.gender.data email = form.email.data location = form.location.data bio = form.bio.data file = request.files['image'] image = secure_filename(file.filename) created_on = datetime.now().strftime("%a %d %b %Y") file.save(os.path.join("app/static/images", image)) user = UserProfile(uid, firstname, lastname, gender, email, location, bio, image, created_on) db.session.add(user) db.session.commit() flash('USER CREATED SUCESSFULLY', 'success') return redirect(url_for('createuser', error=error)) flash_errors(form) return render_template('createuser.html', form=form, error=error)
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.bio.data print biography #image=form.upload.data now = str(datetime.date.today()) image = request.files['photo'] if allowed_file(image.filename): filename = secure_filename(image.filename) image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) else: flash('Incorrect File Format', 'danger') return redirect(url_for('profile')) user = UserProfile(firstname, lastname, gender, email, location, biography, filename, now) db.session.add(user) db.session.commit() flash('File Saved', 'success') return redirect(url_for('profiles')) return render_template("profile.html", form=form)
def profile(): form = SignUpForm() if request.method == "POST" and form.validate_on_submit(): # file_folder = app.config['UPLOAD_FOLDER'] # Retrieving the User's data from the form first_name = form.first_name.data last_name = form.last_name.data age = form.age.data gender = form.gender.data biography = form.biography.data #Retrieving and Saving User's photo photo = request.files['photo'] photo = secure_filename(photo.filename) photo.save(os.path.join("app/static/uploads", photo)) #Randomly generating the User Identification Number, Username and the date the profile was created userid = random.randint(630000000, 700000000) username = first_name + str(random.randint(10, 100)) profile_created_on = datetime.now().strftime("%a, %d %b %Y") new_user = UserProfile(userid, username, first_name, last_name, biography, gender, age, photo, profile_created_on) db.session.add(new_user) db.session.commit() flash("Your profile was successfully created!", 'success') return redirect(url_for('login')) flash_er(form) return render_template('signup.html', form=form)
def profile(): form=InfoForm() if request.method=='POST': username=request.form['username'] id=random.randint(100,100000) firstname=request.form ['firstname'] lastname=request.form['lastname'] biography=request.form['biography'] age=request.form['age'] gender=request.form['gender'] file=request.files['image'] image=secure_filename(file.filename) file.save(os.path.join('app/static/images')) datejoined = datetime.now().strftime("%a %d %b %Y") user = UserProfile(username, id, firstname,lastname, biography,age,gender,image,datejoined) db.session.add(profile) db.session.commit() flash('User added successfully') return redirect(url_for('profile')) flash_errors(form) return render_template('profile.html', form=form)
def add_profile(): form = ProfileForm() if request.method == 'POST': username = request.form ['username'] id = random.randint(1000000, 1099999) firstname = request.form['firstname'] lastname = request.form['lastname'] age = request.form['age'] biography = request.form['biography'] sex = request.form['sex'] file = request.files['image'] image = secure_filename(file.filename) file.save(os.path.join("simages", image)) password = generate_password_hash(request.form['password']) datejoined= datetime.now().strftime('%Y-%m-%d %H:%M:%S') profile = UserProfile (id, username, firstname, lastname, password, age, biography, sex, image, datejoined) db.session.add(profile) db.session.commit() flash ('User ' + username + ' sucessfully added!', 'success') return redirect (url_for('add_profile')) flash_errors(form) return render_template('add_profile.html', form=form)
def get(self, request, pk, alerttype): try: profile = UserProfile.objects.get(user=pk) except UserProfile.DoesNotExist: user = User.objects.get(id=pk) profile = UserProfile(user=user) profile.save() profile.user_data() if alerttype == u'General': form = GeneralSettingsForm( initial={ 'first_name': profile.user.first_name, 'last_name': profile.user.last_name, 'email_address': profile.user.email, 'enabled': profile.user.is_active, }) else: plugin_userdata = self.model.objects.get(title=alerttype, user=profile) form_model = get_object_form(type(plugin_userdata)) form = form_model(instance=plugin_userdata) return render(request, self.template.template.name, { 'form': form, 'alert_preferences': profile.user_data(), })
def register(request): if request.method == 'POST': user_name = request.POST.get('email', '') password_1 = request.POST.get('password', '') password_2 = request.POST.get('repass', '') register_form = RegisterForm(request.POST) print user_name, password_1 print register_form.errors if register_form.is_valid(): user_profile = UserProfile() user_profile.username = user_name user_profile.email = user_name # 这一步一定要使用make_password将密码生成哈希值,否则数据库中插入的数据是明文,这将导致用户登录时authenticate()认证失败 user_profile.password = make_password(password_1) user_profile.save() return render(request, 'user/login.html') # return HttpResponseRedirect('/user/login/') else: return render(request, 'user/reg.html', {'register_form': register_form}) else: return render(request, 'user/reg.html')
def profile(): form = LoginForm() if request.method == "POST" and form.validate_on_submit(): lastname = form.lastname.data gender = form.gender.data email = form.email.data location = form.location.data now = datetime.datetime.now() firstname = form.firstname.data file = form.upload.data filename = secure_filename(file.filename) biography = form.biography.data user = UserProfile(first_name=firstname, last_name=lastname, gender=gender, email=email, location=location, biography=biography, photo_name=filename, date_created=now) db.session.add(user) db.session.commit() file.save(os.path.join(filefolder, filename)) flash('Successfully added.', 'success') return redirect(url_for('profiles')) return render_template("profile.html", form=form)
def addProfile(): form = ProfileForm() if request.method == 'POST' and form.validate_on_submit(): fname = request.form['fname'] lname = request.form['lname'] gender = request.form['gender'] email = request.form['email'] location = request.form['location'] bio = request.form['bio'] images = app.config["UPLOAD_FOLDER"] image = request.files['photo'] image_name = secure_filename(image.filename) image.save(os.path.join(images, image_name)) while True: userid = random.randint(1, 9999999) result = UserProfile.query.filter_by(userid=userid).first() if result is None: break created_on = time.strftime("%d %b %Y") new_profile = UserProfile(fname, lname, gender, email, location, bio, image_name, userid, created_on) db.session.add(new_profile) db.session.commit() flash('New profile sucessfully added', 'success') return redirect(url_for('profiles')) return render_template('addProfile.html', form=form)
def save(self, profile_callback=None): """ Create the new ``User`` and ``RegistrationProfile``, and returns the ``User``. This is essentially a light wrapper around ``RegistrationProfile.objects.create_inactive_user()``, feeding it the form data and a profile callback (see the documentation on ``create_inactive_user()`` for details) if supplied. """ new_user = RegistrationProfile.objects.create_inactive_user( username=self.cleaned_data['username'], password=self.cleaned_data['password1'], email=self.cleaned_data['email'], profile_callback=profile_callback) new_user.first_name = self.cleaned_data['first_name'] new_user.last_name = self.cleaned_data['last_name'] new_user.save() new_profile = UserProfile( user=new_user, fiscale_code=self.cleaned_data['codice_fiscale'], telephone=self.cleaned_data['telefono'], area=self.cleaned_data['area'], personal_data=self.cleaned_data['personal_data'], ) new_profile.save() return new_user
def join(request): if request.method == 'POST': if not request.POST.get('agree'): return HttpResponse() if request.is_ajax(): #form = UserCreationForm(request.POST) if form.is_valid(): form.save() user = authenticate(username=request.POST.get('username'), password=request.POST.get('password1')) if user is not None: if user.is_active: user_profile = UserProfile(user=user) user_profile.save() login(request, user) subject = "Welcome to Coder Bounty!" body = "Thank you for joining Coder Bounty! Enjoy the site. http://coderbounty.com" send_mail( subject, body, "Coder Bounty<" + settings.SERVER_EMAIL + ">", [request.POST.get('email')]) return render_to_response( "login_bar.html", {}, context_instance=RequestContext(request)) else: return HttpResponse() return HttpResponse()