def register(request): context = dict() if request.method == 'POST': form = RegisterForm(request.POST) print 'form' if form.is_valid(): account = form.cleaned_data['account'] password = form.cleaned_data['password'] remember = form.cleaned_data['remember'] phone = form.cleaned_data['phone'] department = form.cleaned_data['department'] city = form.cleaned_data['city_list'] sex = form.cleaned_data['sex'] user = User.objects.create_user(username=account, password=password) user = authenticate(username=account, password=password) dper = Dper.objects.create(user=user, city=city, department=department, phone=phone, sex=sex) if user is not None: dper.save() login(request, user) return redirect('/', context) else: context['form'] = form return render(request, 'member/register.html', context) else: context['form'] = RegisterForm() return render(request, 'member/register.html', context)
def test_empty_email_register_form(self): data = { 'email': '', 'username': '******', 'password': '******', 'password_confirm': 'ZePassword' } form = RegisterForm(data=data) self.assertFalse(form.is_valid())
def test_empty_spaces_pseudo_register_form(self): data = { 'email': '*****@*****.**', 'username': '******', 'password': '******', 'password_confirm': 'ZePassword' } form = RegisterForm(data=data) self.assertFalse(form.is_valid())
def test_password_match_pseudo_password_register_form(self): data = { 'email': '*****@*****.**', 'username': '******', 'password': '******', 'password_confirm': 'ZeTester' } form = RegisterForm(data=data) self.assertFalse(form.is_valid())
def test_valid_register_form(self): data = { 'email': '*****@*****.**', 'username': '******', 'password': '******', 'password_confirm': 'ZePassword' } form = RegisterForm(data=data) self.assertTrue(form.is_valid())
def test_too_long_password_register_form(self): data = { 'email': '*****@*****.**', 'username': '******', 'password': stringof77chars, 'password_confirm': stringof77chars } form = RegisterForm(data=data) self.assertFalse(form.is_valid())
def test_forbiden_email_provider_register_form(self): data = { 'email': '*****@*****.**', 'username': '******', 'password': '******', 'password_confirm': 'ZePassword' } form = RegisterForm(data=data) self.assertFalse(form.is_valid())
def test_pseudo_coma_register_form(self): ProfileFactory() data = { 'email': '*****@*****.**', 'username': '******', 'password': '******', 'password_confirm': 'ZePassword' } form = RegisterForm(data=data) self.assertFalse(form.is_valid())
def test_email_exist_register_form(self): testuser = ProfileFactory() data = { 'email': testuser.user.email, 'username': '******', 'password': '******', 'password_confirm': 'ZeTester' } form = RegisterForm(data=data) self.assertFalse(form.is_valid())
def post(self, request, *args, **kwargs): form = RegisterForm(data=request.data) check_or_business_error(form.is_valid(), error_code='1000', error_data=form.errors) user = User.objects.create_user( form.validated_data['mobile'], form.validated_data['password'], form.validated_data['nickname'], ) check_or_business_error(user is not None, '1003') login(request, user) user_data = UserDetailSerializer(user).data return success_rsp(user_data)
def register(request): context = dict() if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): account = form.cleaned_data['account'] password = form.cleaned_data['password'] remember = form.cleaned_data['remember'] user = User.objects.create_user(username=account, password=password) user = authenticate(username=account, password=password) if user is not None: login(request, user) return redirect('/', context) else: context['form'] = form return render(request, 'member/register.html', context) else: context['form'] = RegisterForm() return render(request, 'member/register.html', context)
def register(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): data = form.cleaned_data salt = sha_constructor(str(random.random())).hexdigest()[:5] activation_code = sha_constructor(salt+data['username']).hexdigest() user_temp = form.save(commit=False) user_temp.activation_code = activation_code user_temp.post_code = request.POST['zipcode'] user_temp.county = request.POST['county'] user_temp.district = request.POST['district'] user_temp.save() html_content = render_to_string('email/activate.html', { 'host': request.get_host(), 'STATIC_URL': settings.STATIC_URL, 'activation_code': activation_code, 'name': user_temp.first_name, 'username': user_temp.username, 'password': user_temp.password }) subject = _('EMPOR Account Activation') message = EmailMessage(subject, html_content, settings.DEFAULT_FROM_EMAIL, [user_temp.email]) message.content_subtype = "html" message.send() complete_url = "%s?username=%s&email=%s" % \ (reverse('member-register-complete'), user_temp.username, user_temp.email) return redirect(complete_url) else: form = RegisterForm() return render(request, 'member/register.html', {'form': form})
def facebook_connect_new(request): profile = request.session.get('facebook_profile', None) if not profile: return redirect('/') if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): user_temp = form.save(commit=False) user_temp.post_code = request.POST['zipcode'] user_temp.county = request.POST['county'] user_temp.district = request.POST['district'] user_temp.save() # create user user = User.objects.create_user(user_temp.username, profile['email'], user_temp.password) user.first_name = user_temp.first_name user.last_name = user_temp.last_name user.save() # user profile user_profile = UserProfile( user = user, gender = user_temp.gender, phone = user_temp.phone, birthday = user_temp.birthday, county = user_temp.county, district = user_temp.district, country = user_temp.country, post_code = user_temp.post_code, address = user_temp.address, ) user_profile.save() # facebook profile fbprofile = FacebookProfile( uid = profile['id'], user = user, name = profile.get('name', ''), gender = profile.get('gender', 'male'), locale = profile['locale'], url = profile['link'], timezone = profile.get('timezone', ''), verified = profile.get('verified', False), created_at = datetime.now() ) fbprofile.save() # login user user = auth.authenticate(username=user.username, password=user_temp.password) auth.login(request, user) user_temp.delete() request.session['fb_connect_type'] = 'new' return redirect('member-facebook-connect-done') else: username = profile.get('username', '') birthday = profile.get('birthday', None) if birthday: birthday = birthday.split('/') birthday = birthday[2] + '/' + birthday[0] + '/' + birthday[1] gender = profile.get('gender', 0) first_name = profile.get('first_name', '') last_name = profile.get('last_name', '') email = profile.get('email', '') form = RegisterForm(initial={ 'username': username, 'birthday': birthday, 'gender': gender, 'first_name': first_name, 'last_name': last_name, 'email': email, }) return render(request, 'member/facebook/new.html', {'profile': profile, 'form': form})