def register_user(request): #import pdb; pdb.set_trace() result_obj = json.loads(request.body) username = result_obj['email'] email = result_obj['email'] name = result_obj['name'] password = result_obj['password'] New_User = User_Profile() return_msg = {"msg" : "Success"} try: if User.objects.filter(username=username).exists(): return_msg['msg'] = "Username already exists" else: user = User.objects.create_user(username, email=email, password=password, first_name= name) New_User.user = user New_User.user_type = result_obj['user_type'] New_User.save() user_acc = authenticate(username=username, password=password) if user_acc: if user_acc.is_active: login(request, user_acc) check_and_clear_free_radical(New_User) return JsonResponse(return_msg) else: return_msg['msg'] = "Error Occoured. Please Try Again" return JsonResponse(return_msg) except Exception, e: return_msg['msg'] = e
def run_query(name, animal, pic, loc, contact, bio_): animal_prof = User_Profile(pet_name=name, a_type=animal, p_pic=pic, location=loc, contact_info=contact, bio=bio_) prof_key = animal_prof.put()
def createUserFromFacebook(login_session): new_user_profile = User_Profile(first_name = login_session['firstname'], last_name = login_session['lastname'],username=login_session['username'], email=login_session['email'].decode('utf-8')) session.add(new_user_profile) session.commit() user = session.query(User_Profile).filter_by(email=login_session['email']).first(); new_facebook_account = Facebook_Account(user_profile_id=user.id, facebook_id=login_session['google_id']) session.add(new_facebook_account) session.commit() return user.id
def get(self): all_profiles_template = the_jinja_env.get_template( 'templates/all_profiles.html') all_profiles = User_Profile.query().fetch() the_variable_dict = {'all_profiles': all_profiles} self.response.write(all_profiles_template.render(the_variable_dict))
def register_user(request): #import pdb; pdb.set_trace() result_obj = json.loads(request.body) username = result_obj['email'] email = result_obj['email'] name = result_obj['name'] password = result_obj['password'] New_User = User_Profile() return_msg = {"msg": "Success"} try: if User.objects.filter(username=username).exists(): return_msg['msg'] = "Username already exists" else: user = User.objects.create_user(username, email=email, password=password, first_name=name) New_User.user = user New_User.user_type = result_obj['user_type'] New_User.save() user_acc = authenticate(username=username, password=password) if user_acc: if user_acc.is_active: login(request, user_acc) check_and_clear_free_radical(New_User) return JsonResponse(return_msg) else: return_msg['msg'] = "Error Occoured. Please Try Again" return JsonResponse(return_msg) except Exception, e: return_msg['msg'] = e
def signup(): if request.method == 'GET': return render_template('signup.html') else: email = request.form.get('email') username = request.form.get('username') firstname = request.form.get('firstname') lastname = request.form.get('lastname') password = request.form.get('pwd') password_confirm = request.form.get('pwd_confirm') print email print "email above" if email is None or email == "" or password is None or password=="" or username is None or username == "": print "OK heres" return "Missin argument, emial username and password field could not be empty" if password != password_confirm: return "Password not match" #check if user profile with the same email address exist or not in the database user = session.query(User_Profile).filter_by(email=email).first() if user is not None: flash ("user with email address %s already exist" %email) return redirect('signup') new_user_profile = User_Profile(first_name=firstname, last_name=lastname, username=username, email=email) session.add(new_user_profile) session.commit() user = session.query(User_Profile).filter_by(email=email).first() new_user = User(user_profile_id=user.id, username=username, email=email, password_hash=password) new_user.hash_password(password) session.add(new_user) session.commit() flash ("user created successfully!") return redirect('signup')
def register(request): otherVars = {'pageType': 'register'} # if request method is post if request.method == 'POST': regForm = registerForm(request.POST) userIns = User() userIns.email = request.POST['email'] userIns.username = request.POST['email'] userIns.set_password(request.POST['password']) userIns.first_name = request.POST['first_name'] userIns.last_name = request.POST['last_name'] try: userIns.save() except: return HttpResponseRedirect(reverse('register')) userIns2 = User_Profile() userIns2.user_id = userIns.id userIns2.contact_num = request.POST['contact_num'] userIns2.save() return HttpResponseRedirect(reverse('login')) else: regForm = registerForm() # Define header groups hgrps = ( { 'name': 'Sign Up Information', 'lblwidth': '160' }, { 'name': 'Personal Information', 'lblwidth': '160' }, ) # For first header group regForm.fields["email"].widget.attrs['hgrp'] = '0' regForm.fields["email"].widget.attrs['wsize'] = '300' regForm.fields["password"].widget.attrs['hgrp'] = '0' regForm.fields["password"].widget.attrs['wsize'] = '300' regForm.fields["confirm_password"].widget.attrs['hgrp'] = '0' regForm.fields["confirm_password"].widget.attrs['wsize'] = '300' # For first header group regForm.fields["first_name"].widget.attrs['hgrp'] = '1' regForm.fields["first_name"].widget.attrs['wsize'] = '300' regForm.fields["last_name"].widget.attrs['hgrp'] = '1' regForm.fields["last_name"].widget.attrs['wsize'] = '300' regForm.fields["contact_num"].widget.attrs['hgrp'] = '1' regForm.fields["contact_num"].widget.attrs['wsize'] = '300' regForm.fields["contact_num"].label = 'Contact number' return render(request, 'main/register.html', { 'otherVars': otherVars, 'regForm': regForm, 'hgrps': hgrps, })
def clear_userprofiles(): all_profiles = User_Profile.query().fetch() for entity in all_profiles: entity.key.delete()