def setup(request): sans_facebook = True if request.GET.has_key( 'sans_facebook') and request.GET['sans_facebook'] else False redirect_to = request.GET.get('redirect_to', "/") form = CreateAccountForm(initial={ 'redirect_to': redirect_to, }) if request.POST: sans_facebook = True if request.POST.has_key( 'sans_facebook') and request.POST['sans_facebook'] else False form = CreateAccountForm(request.POST) if form.is_valid(): u = User() u.bio = form.cleaned_data['bio'] u.birth_year = form.cleaned_data['birth_year'] u.email = u.long_email = form.cleaned_data['email'] u.fb_access_token = form.cleaned_data['fb_access_token'] u.gender = form.cleaned_data['gender'] u.first_name = form.cleaned_data['first_name'] u.last_name = form.cleaned_data['last_name'] u.facebook_id = form.cleaned_data['fbid'] u.bio = u.bio.encode('utf-8') if u.bio else "" u.first_name = u.first_name.encode('utf-8') if u.first_name else "" u.last_name = u.last_name.encode('utf-8') if u.last_name else "" if form.cleaned_data['location_data']: u.location = Location.get_or_create( form.cleaned_data['location_data']) u.next_email_time = datetime.datetime.now() + timedelta(days=1) u.username = create_handle('%s%s' % (u.first_name, u.last_name)) u.password = hash_password(form.cleaned_data['password']) u.save() Subscription.get_or_create(user=u, pub_id=NOTIFICATIONS_PUB) #Post to Facebook if form.cleaned_data['post_to_facebook']: fb_helpers.post_joined_to_wall(u) cache.put_on_handle(u, u.username) redirect_to = form.cleaned_data['redirect_to'] or '/' #perform for all that login magic that happens under the covers attempt_login(request, u.username, form.cleaned_data["password"]) return set_auth_cookies(HttpResponseRedirect(redirect_to), u) return render( request, 'user/setup.html', { 'title': 'Setup your account', 'create_form': form, 'sans_facebook': sans_facebook, })
def get_user(parameters): user = User() id_regex = '(.*)([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)' re_result = re.search(id_regex, parameters) server = re_result.group(1) profile_id = re_result.group(2) ##double check id is not our server id server_user = User.objects.filter(id=profile_id) if server_user: return server_user[0] response = try_api_service(server, profile_id) print("RESPONE", response) try: user.username = response['displayName'] re_result = re.search(id_regex, response['id']) user.id = re_result.group(2) user.host = response['host'] user.bio = optional_attributes(user.bio, response, 'bio') user.first_name = optional_attributes(user.first_name, response, 'firstname') user.last_name = optional_attributes(user.last_name, response, 'lastname') user.email = optional_attributes(user.email, response, 'email') return user except: return False return False
def setup(request): sans_facebook = True if request.GET.has_key('sans_facebook') and request.GET['sans_facebook'] else False redirect_to = request.GET.get('redirect_to', "/") form = CreateAccountForm(initial={'redirect_to': redirect_to,}) if request.POST: sans_facebook = True if request.POST.has_key('sans_facebook') and request.POST['sans_facebook'] else False form = CreateAccountForm(request.POST) if form.is_valid(): u = User() u.bio = form.cleaned_data['bio'] u.birth_year = form.cleaned_data['birth_year'] u.email = u.long_email = form.cleaned_data['email'] u.fb_access_token = form.cleaned_data['fb_access_token'] u.gender = form.cleaned_data['gender'] u.first_name = form.cleaned_data['first_name'] u.last_name = form.cleaned_data['last_name'] u.facebook_id = form.cleaned_data['fbid'] u.bio = u.bio.encode('utf-8') if u.bio else "" u.first_name = u.first_name.encode('utf-8') if u.first_name else "" u.last_name = u.last_name.encode('utf-8') if u.last_name else "" if form.cleaned_data['location_data']: u.location = Location.get_or_create(form.cleaned_data['location_data']) u.next_email_time = datetime.datetime.now() + timedelta(days = 1) u.username = create_handle('%s%s' % (u.first_name, u.last_name)) u.password = hash_password(form.cleaned_data['password']) u.save() Subscription.get_or_create(user = u, pub_id = NOTIFICATIONS_PUB) #Post to Facebook if form.cleaned_data['post_to_facebook']: fb_helpers.post_joined_to_wall(u) cache.put_on_handle(u, u.username) redirect_to = form.cleaned_data['redirect_to'] or '/' #perform for all that login magic that happens under the covers attempt_login(request, u.username, form.cleaned_data["password"]) return set_auth_cookies(HttpResponseRedirect(redirect_to), u) return render(request, 'user/setup.html', { 'title' : 'Setup your account', 'create_form' : form, 'sans_facebook': sans_facebook, })