def test_email_is_saved(self): form = RegistrationForm(data=self.data) self.assertTrue(form.is_valid()) user = form.save() self.assertEqual(user.email, '*****@*****.**')
def register(request): if request.is_ajax(): if request.POST['fratname'] and request.POST['university'] and request.POST['email'] and request.POST['type']: try: uni = University.objects.get(name=str(request.POST['university'])) except University.DoesNotExist: uni = University(name=str(request.POST['university']), date = datetime.now()) uni.save() form = RegistrationForm(request.POST) clean = form.is_valid() # Make some dicts to get passed back to the browser rdict = {'bad':'false'} errors = "" if not clean: rdict.update({'bad':'true'}) for e in form.errors.iteritems(): errors += str(e[1]) else: date = datetime.now() org = Organization(university = uni, name=request.POST['fratname'], date = date, type=request.POST['type']) org.save() user = User.objects.create_user(request.POST['email'], request.POST['email'], date.isoformat()) user.save() user.get_profile().chapter = org user.get_profile().university = uni user.get_profile().ip = request.META['REMOTE_ADDR'] user.get_profile().save json = simplejson.dumps(rdict) return HttpResponse(errors) return HttpResponse("fail")
def new_activation_link( request, user_id ): # check if it's the same user and if they are already authed # new email not being sent form = RegistrationForm() datas = {} user = User.objects.get(username=user_id) if user is not None and not user.is_active: #here datas['username'] = user.username datas['email'] = user.email datas['email_path'] = "path_to/ResendEmail.txt" datas['email_subject'] = "Welcome to site_name" salt = hashlib.sha1(str( random.random()).encode('utf-8')).hexdigest()[:5] usernamesalt = datas['email'] if isinstance(usernamesalt, str): usernamesalt = str.encode(usernamesalt) if isinstance(salt, str): salt = str.encode(salt) datas['activation_key'] = hashlib.sha1(salt + usernamesalt).hexdigest() profil = Profil.objects.get(user=user) profil.activation_key = datas['activation_key'] profil.key_expires = timezone.now() + datetime.timedelta(days=1) # generate public child from wallet file here profil.save() form.sendEmail(datas) request.session['new_link'] = True #Display : new link send return render(request, 'register_page.html', {'email_sent': True}) else: return render(request, 'home.html')
def hello(request, template="users/login.html"): cc = {} login_form = LoginForm() registration_form = RegistrationForm() if request.method == "POST" and "login_submit" in request.POST: login_form = LoginForm(request.POST) if login_form.is_valid(): user = authenticate( username=login_form.cleaned_data["username"], password=login_form.cleaned_data["password"] ) login(request, user) messages.add_message(request, messages.SUCCESS, "Zostałeś zalogowany.") if "next" in request.GET: return HttpResponseRedirect(request.GET["next"]) else: return HttpResponseRedirect(reverse("index")) elif request.method == "POST" and "registration_submit" in request.POST: registration_form = RegistrationForm(request.POST) if registration_form.is_valid(): user_profile = registration_form.save() user = authenticate( username=registration_form.cleaned_data["username"], password=registration_form.cleaned_data["password1"], ) # send_registration_mail(request.LANGUAGE_CODE, registration_form.cleaned_data['email'], user_profile.activation_key) return registered(request) cc["login_form"] = login_form cc["registration_form"] = registration_form return render(request, template, Context(cc))
def new_activation_link(request, user_id): form = RegistrationForm() datas = {} user = Users.objects.get(id=user_id) if user is not None and not user.is_active: datas['first_name'] = user.first_name datas['last_name'] = user.last_name datas['username'] = user.username datas['email_path'] = "/ResendEmail.txt" datas['email_subject'] = _("New activation key for CMS") salt = hashlib.sha1(str(random.random())).hexdigest()[:5] usernamesalt = datas['username'] if isinstance(usernamesalt, unicode): usernamesalt = usernamesalt.encode('utf8') datas['activation_key'] = hashlib.sha1(salt + usernamesalt).hexdigest() profile = Profile.objects.get(user=user) profile.activation_key = datas['activation_key'] profile.key_expires = datetime.datetime.strftime( datetime.datetime.now() + datetime.timedelta(days=2), "%Y-%m-%d %H:%M:%S") profile.save() form.sendEmail(datas) request.session['new_link'] = True #Display: new link sent return render(request, 'register.html', { 'u': settings.CMS_URL, 'lpl': lpl }, locals()) else: return redirect(settings.CMS_URL)
def waiting_list(request): title = "Registration" definition = get_object_or_404(ZosiaDefinition, active_definition=True) date_1, date_2, date_3, date_4 = definition.zosia_start, (definition.zosia_start + timedelta(days=1)),\ (definition.zosia_start + timedelta(days=2)),\ (definition.zosia_start + timedelta(days=3)) if request.POST: form = WaitingForm(request.POST) user_form = RegistrationForm(request.POST) f1 = form.is_valid() f2 = user_form.is_valid() if f1 and f2: user = user_form.save() send_confirmation_mail(request, user, definition) waiting = form.save(commit=False) waiting.state = definition waiting.user = user waiting.save() return HttpResponseRedirect('/register/thanks/') form = WaitingForm(request.POST) user_form = RegistrationForm(request.POST) return render_to_response('waiting.html', {'pref_form': form, 'user_form': user_form, 'date_1': date_1, 'date_2': date_2, 'date_3': date_3, 'date_4': date_4, 'definition': definition})
def login(request): login_form = LoginForm() register_form = RegistrationForm() next = request.REQUEST.get('next') if 'kind' in request.POST: if request.POST['kind'] == 'login': login_form = LoginForm(request.POST) if login_form.is_valid(): username = login_form.get_username() request.session['username'] = username if next: return HttpResponseRedirect(next) return HttpResponseRedirect('/') elif request.POST['kind'] == 'register': register_form = RegistrationForm(request.POST) if register_form.is_valid(): username = register_form.save() request.session['username'] = username if next: return HttpResponseRedirect(next) return HttpResponseRedirect('/') context = { 'login_form': login_form, 'register_form': register_form, 'next': next, } return render_to_response( 'users/login.html', context, context_instance=RequestContext(request))
def register(request): if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): data = form.cleaned_data new_customer = Customer() # Stock django User model fields new_customer.username = data['id_number'] new_customer.set_password(data['password']) new_customer.first_name = data['first_name'] new_customer.last_name = data['last_name'] new_customer.email = data['email'] # Our custom properties new_customer.phone_number = data['phone_number'] new_customer.address = data['address'] new_customer.save() return HttpResponseRedirect(reverse("register_thanks")) else: form = RegistrationForm() return render(request, "users/register.html", {"form": form})
def register(request): if is_registration_disabled(): raise Http404 if not is_free_rooms(): return HttpResponseRedirect('/waiting/') title = "Registration" definition = get_object_or_404(ZosiaDefinition, active_definition=True) date_1, date_2, date_3, date_4 = definition.zosia_start, (definition.zosia_start + timedelta(days=1)),\ (definition.zosia_start + timedelta(days=2)),\ (definition.zosia_start + timedelta(days=3)) user_form = RegistrationForm(request.POST or None) pref_form = preferences_form_fabric(definition)(request.POST or None) org_form = OrganizationForm(request.POST or None) f1 = user_form.is_valid() f2 = pref_form.is_valid() f3 = org_form.is_valid() if f1 and f2 and f3: user = user_form.save() org = org_form.save() send_confirmation_mail(request, user, definition) preference = pref_form.save(commit=False) preference.user = user preference.org = org preference.state = definition preference.save() return HttpResponseRedirect('/register/thanks/') return render_to_response('register_form.html', locals())
def register(request): if request.POST: form = RegistrationForm(request.POST, request.FILES) if form.is_valid(): user = form.save() email = user.email first_name = "Claper" activation_key = create_activation_key(email) key_expires = datetime.datetime.now() + datetime.timedelta(2) Activation.objects.create(user=user, activation_key=activation_key, key_expires=key_expires) send_activation_key(email, activation_key, first_name) #return redirect('/success/') resp = {"code": "0"} resp = json.dumps(resp) return HttpResponse(resp, content_type="application/json") else: #resp = {"response": "fail", 'error': form['email'].errors} resp = {"code": "1"} resp = json.dumps(resp) return HttpResponse(resp, content_type="application/json") form = RegistrationForm() return render(request, 'signup.html', {'form': form})
def guest(request): login_form = LoginForm(data=request.POST or None, prefix="login") register_form = RegistrationForm(data=request.POST or None, prefix="register") if request.POST: import pdb pdb.set_trace() if login_form.is_valid(): user = login_form.login() if user.is_active: login(request, user) return redirect('users:index') else: messages.error(request, 'This account has been deleted.') return redirect('users:guest') elif register_form.is_valid(): user = register_form.save() # FIXME change to validation email later login(request, user) return redirect('users:index') return render(request, "users/guest.html", { "login_form": login_form, "register_form": register_form })
def start(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): # user = User.objects.create_user( # username=form.cleaned_data['username'], # password=form.cleaned_data['password1'], # email=form.cleaned_data['email'] # ) user = User(username=form.cleaned_data['username'], password=form.cleaned_data['password1'], email=form.cleaned_data['email']) user.save() return HttpResponseRedirect('/users/success/') else: form = RegistrationForm() # 로그인 세션 확인 # 아이디와 비밀번호 비교해서 로그인 성공 시 'login_info' 세션 생성해서 아이디 저장 # request.session['login_info'] = "~~~id" 하고 is_login = TRUE 로 변경 if request.session.get('login_info', False): is_login = True else: is_login = False print(is_login) variables = RequestContext(request, { 'form': form, 'is_login': is_login, }) return render_to_response( 'torch/start.html', variables, )
def register(request): """ Es invocada cuando hacemos un nuevo registro y se encarga de recoger los datos y almacenarlos. """ state = " Se dispone a realizar un nuevo registro.Recuerde que todos los campos son obligatorios" if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): name_user = form.cleaned_data['username'] email_user = form.cleaned_data['email'] pass_user = form.cleaned_data['password1'] create_user = User.objects.create_user(username= name_user, email= email_user, password=pass_user) create_user.save() pseudo = "@"+name_user extend = ExtendUser(user=create_user, pseudo=pseudo) extend.save() return redirect('/login') else: state = " Error en el registro" return render_to_response('nuevo.html', {'title':'Registro', 'formulario': form, 'state':state}, context_instance=RequestContext(request)) else: form = RegistrationForm() return render_to_response('nuevo.html', {'title':'Registro', 'formulario': form, 'state':state}, context_instance=RequestContext(request))
def register_page(request): """ User can register here to get an account :param request: HTTP request :return: HTTP response """ if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): user = User.objects.create_user( username=form.cleaned_data.get('username'), password=form.cleaned_data.get('password'), email=form.cleaned_data.get('email') ) user.save() subscription = Subscription(name=user, registration_date=datetime.now(), last_login_date=datetime.now(), abo_date=datetime.now() + timedelta(days=30)) subscription.save() return render(request, "users/register_success.html", {'username': form.cleaned_data['username']}) else: form = RegistrationForm() return render(request, "users/register.html", {"form": form})
def post(self, request): form = RegistrationForm(request.POST) if form.is_valid(): form.save() return redirect('users:login') else: messages.warning(request, 'Try Again') return redirect('users:register')
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.register(request) return redirect('users.views.home') else: form = RegistrationForm() return render(request, 'register.hisp', {'form': form})
def test_saves_new_user(self): form = RegistrationForm({ 'username': '******', 'password1': 'testpassword123', 'password2': 'testpassword123', }) new_user = form.save() self.assertEqual(User.objects.count(), 1) self.assertEqual(User.objects.first(), new_user)
def test_if_valid_on_all_required_fields(self): form_data = { 'username': '******', 'email': '*****@*****.**', 'is_teacher': False, 'password1': 'example', 'password2': 'example' } form = RegistrationForm(data=form_data) self.assertTrue(form.is_valid())
def test_if_not_valid_on_different_passwords(self): form_data = { 'username': '******', 'email': '*****@*****.**', 'is_teacher': True, 'password1': 'example', 'password2': 'example2' } form = RegistrationForm(data=form_data) self.assertFalse(form.is_valid())
def test_if_not_valid_on_empty_field(self): form_data = { 'username': '', 'email': '*****@*****.**', 'is_teacher': False, 'password1': 'example', 'password2': 'example' } form = RegistrationForm(data=form_data) self.assertFalse(form.is_valid())
def register(request): form = RegistrationForm(request.POST or None) if request.POST and form.is_valid(): form.save() user = authenticate(username=request.POST['username'], password=request.POST['password']) auth_login(request, user) return render(request, 'registration/register_complete.html') return render(request, 'registration/register.html', {'form': form})
def test_user_submits_empty_form(self): form_data = {'name': '', 'email': '', 'password': ''} from users.forms import RegistrationForm form = RegistrationForm(form_data) self.assertFalse(form.is_valid()) self.assertTrue(form.errors) self.assertTrue(form.errors.get('name')) self.assertTrue(form.errors.get('email')) self.assertTrue(form.errors.get('password'))
def test_user_submits_invalid_data(self): form_data = {'name': 'Adnan', 'email': 'nonemail', 'password': '******'} from users.forms import RegistrationForm form = RegistrationForm(form_data) self.assertFalse(form.is_valid()) self.assertTrue(form.errors) self.assertFalse(form.errors.get('name')) self.assertTrue(form.errors.get('email')) self.assertFalse(form.errors.get('password'))
def test_user_submits_valid_duplicate_data(self): form_data = {'name': 'Nanda Kishore', 'email': '*****@*****.**', 'password': '******'} from users.forms import RegistrationForm form = RegistrationForm(form_data) self.assertFalse(form.is_valid()) self.assertTrue(form.errors) self.assertFalse(form.errors.get('name')) self.assertTrue(form.errors.get('email')) self.assertFalse(form.errors.get('password'))
def post(self, request, *args, **kwargs): form = RegistrationForm(request.POST) password = request.POST.get('password') if form.is_valid(): user = form.save(commit=False) user.set_password(password) user.save() messages.success(request, 'User Succefully registered.') return HttpResponseRedirect('/') ctx = {"form": form} return render(request, "registration/register.html", ctx)
def post(self, *args, **kwargs): form = RegistrationForm(self.request.POST) if form.is_valid(): user = form.save(commit=False) user.user_name = form.cleaned_data['username'] user.email = form.cleaned_data['email'] user.set_password(form.cleaned_data['password']) user.save() return HttpResponseRedirect(reverse('bookmark_create')) return render(self.request, 'registration/register.html', {'form': form})
def post(self, request): form = RegistrationForm(request.POST) if form.is_valid(): new_user = form.save() new_user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1'], ) login(request, new_user) return redirect('/') else: return render(request, 'users/register.html', {'form': form})
def test_user_submits_valid_form(self): form_data = {'name': 'Adnan', 'email': '*****@*****.**', 'password': '******'} from users.forms import RegistrationForm form = RegistrationForm(form_data) self.assertTrue(form.is_valid()) self.assertFalse(form.errors) self.assertTrue(form.cleaned_data) self.assertEquals(form.cleaned_data.get('name'), form_data['name']) self.assertEquals(form.cleaned_data.get('email'), form_data['email']) self.assertEquals(form.cleaned_data.get('password'), form_data['password'])
def register(request): """ Allows creation of a new user. """ form = RegistrationForm(request.DATA) if form.is_valid(): key = form.save() data = { 'token': key } return OK_RESPONSE(data) else: return BAD_RESPONSE(form.errors)
def test_register_form_is_valid(self): form = RegistrationForm( data={ 'username': '******', 'email': '*****@*****.**', 'password1': 'sdfeeeg123', 'password2': 'sdfeeeg123', 'first_name': 'lot', 'last_name': 'tot' }) self.assertTrue(form.is_valid())
def signup(request): user = request.user if user.is_authenticated(): return HttpResponseRedirect(reverse_lazy('dashboard')) form = RegistrationForm() if request.method == 'POST': form = RegistrationForm(data=request.POST) if form.is_valid(): email = form.cleaned_data['email'] password = form.cleaned_data['password'] existing_user = get_object_or_None(AuthUser, email=email) if existing_user: msg = _('That email already belongs to someone, please login:'******'Login Successful') messages.success(request, msg) return HttpResponseRedirect(reverse_lazy('dashboard')) elif request.method == 'GET': # Preseed name and/or email if passed through GET string email = request.GET.get('e') full_name = request.GET.get('name') if email or full_name: form = RegistrationForm(initial={ 'email': email, 'full_name': full_name, }) return { 'form': form, 'is_input_page': True, }
def test_register_form_email_umk_not_valid(self): form = RegistrationForm( data={ 'username': '******', 'email': '*****@*****.**', 'password1': 'sdfeeeg123', 'password2': 'sdfeeeg123', 'first_name': 'lot', 'last_name': 'tot' }) self.assertFalse(form.is_valid()) self.assertEqual(len(form.errors), 1, form.errors)
def handle_signup(request): """Helper function for signups.""" if request.method == 'POST': form = RegistrationForm(data=request.POST) if form.is_valid(): profile = Profile.objects.create_profile( username=form.cleaned_data['username'], password=form.cleaned_data['password'], email=form.cleaned_data['email'], ) profile.send_confirmation_email() return form return RegistrationForm()
def signup(request): form = RegistrationForm() if request.method == "POST": form = RegistrationForm(data=request.POST) if form.is_valid(): user = form.save() activation_key = hashlib.sha224(user.username.encode("utf-8")).hexdigest() key_expires = timezone.now() + datetime.timedelta(1) profile = UserProfile(user=user, activation_key=activation_key, key_expires=key_expires) profile.save() send_email(user, profile) messages.info(request, "Check email for a confirmation link!") return redirect("/") return render(request, "signup.html", {"form": form})
def signup(): if 'email' in session: return redirect('/messages') form = RegistrationForm() if form.validate_on_submit(): user = User(name=form.name.data, email=form.email.data, password=form.password.data) db.session.add(user) db.session.commit() flash(f'Account created for {form.name.data}', 'success') return redirect('/login') return render_template('users/signup.html', title='Register', form=form)
def register(request): if request.user.is_authenticated(): # They already have an account; don't let them register again return render_to_response( 'users/register.html', {'has_account': True}, context_instance=RequestContext(request) ) if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): # Save the user user = form.save(form) # user.groups.add(Group.objects.get(name='Regular')) # Build the activation key for their account salt = hashlib.md5(str(random.random())).hexdigest()[:5] activation_key = hashlib.md5(salt+user.username).hexdigest() key_expires = datetime.datetime.today() + datetime.timedelta(2) # Create and save their profile new_profile = UserProfile(user=user, activation_key=activation_key, key_expires=key_expires) new_profile.save() # Send an email with the confirmation link EMAIL_SUBJECT = 'The signup information you requested' #TODO: remove the following two lines current_site = Site.objects.get_current() c = Context({'user': user.username, 'key': new_profile.activation_key, 'site_name': current_site.domain}) # c = Context({'user': user.username, 'key': new_profile.activation_key}) EMAIL_BODY = (loader.get_template('users/mails/user_signup.txt')).render(c) send_mail(EMAIL_SUBJECT, EMAIL_BODY, FROM_EMAIL, [user.email]) # messages.success(request, u'Welcome to the PhoneLab Web Site!') return render_to_response( 'users/register.html', { 'created': True, 'mail' : user.email }, context_instance=RequestContext(request) ) else: form = RegistrationForm() return render_to_response( 'users/register.html', { 'form': form }, context_instance=RequestContext(request) )
def register(request): if request.user.is_authenticated(): # They already have an account; don't let them register again return render_to_response( 'users/register.html', {'has_account': True}, context_instance=RequestContext(request) ) if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): # Find the user type user = form.save(form) user_type = form.cleaned_data['user_type'] # Build the activation key for their account salt = hashlib.md5(str(random.random())).hexdigest()[:5] activation_key = hashlib.md5(salt+user.username).hexdigest() key_expires = datetime.today() + timedelta(2) new_profile = UserProfile(user=user, activation_key=activation_key, key_expires=key_expires, user_type = user_type) current_site = Site.objects.get_current() EMAIL_SUBJECT = 'Phonelab Email Verification' c = Context({'user': user, 'key': new_profile.activation_key, 'site_name': current_site}) EMAIL_BODY = (loader.get_template('users/mails/user_signup.txt')).render(c) TO_EMAIL = [user.email] send_mail(EMAIL_SUBJECT, EMAIL_BODY, FROM_EMAIL, TO_EMAIL) # Create and save their profile new_profile.save() return render_to_response( 'users/register.html', { 'created': True, 'user_type': user_type, 'mail' : user.email }, context_instance=RequestContext(request) ) else: form = RegistrationForm() return render_to_response( 'users/register.html', { 'form': form }, context_instance=RequestContext(request) )
def register(): form = RegistrationForm() if form.validate_on_submit(): user = User(email=form.email.data, username=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() flash('Thank you for registration!') return redirect(url_for('users.login')) return render_template('register.html', form=form)
def post(self, request, *args, **kwargs): """ Validates if the posted form is correct. :param request: :param args: :param kwargs: :return: """ self.object = None form = RegistrationForm(request.POST) if form.is_valid(): return self.form_valid(form) else: return self.form_invalid(form)
def post(self, request): response = {"user": None, "msg": None} form = RegistrationForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] email = form.cleaned_data['email'] password = form.cleaned_data['password2'] # 使用内置User自带create_user方法创建用户,不需要使用save(),且create_user密码自动加密,默认的create密码不加密 user = models.UserInfo.objects.create_user(username=username, password=password, email=email) response['user'] = user.username else: response["msg"] = form.errors return JsonResponse(response)
def UserReg(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): name_user = form.cleaned_data['username'] email_user = form.cleaned_data['email'] pass_user = form.cleaned_data['password1'] pseudo_ = form.cleaned_data['pseudo'] create_user = CustomUser.objects.create_user(username = name_user, email = email_user, password = pass_user, pseudo=pseudo_ ) create_user.save() return redirect('/login') form = RegistrationForm() return render(request,'users/user_form.html', {'title':'Registro', 'form': form})
def register(): ''' this function register user and if user was login user can not come to this page ''' if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') new_user = User(user_name=form.user_name.data, email=form.email.data, password=hashed_password) db.session.add(new_user) db.session.commit() return redirect(url_for('users.login')) return render_template('register.html', title='register', form=form)
def post(self, request): email_or_phone = request.POST['email_or_phone'] form_error = _('Enter correct email or phone') if self.validate_email(email_or_phone): # Reset password by email if User.objects.filter(email=email_or_phone).exists(): # send email self.put_data_to_session(email=email_or_phone) print('! ! ! password - - - - ', self.request.session['password']) return redirect('confirm', confirm=self.confirm) form_error = _('A user with that email no found.') if self.validate_phone(email_or_phone): # Reset password by phone if User.objects.filter(phone=email_or_phone).exists(): # send sms self.put_data_to_session(phone=email_or_phone) print('! ! ! password - - - - ', self.request.session['password']) return redirect('confirm', confirm=self.confirm) form_error = _('A user with that phone no found.') context = { 'form': RegistrationForm(request.POST), 'form_error': form_error } return render(request, self.template_name, context)
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash(f'Your Account has been created! You are now able to log in', 'success') return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def view_register(request, registration_template, next=''): from users.forms import RegistrationForm if request.method == 'POST': form = RegistrationForm(post_data(request)) if form.is_valid(): userprofile = _handle_user_registration(form) from users.messages import USER_SIGNUP_SUCCESSFUL django_messages_framework.success(request, USER_SIGNUP_SUCCESSFUL) return _let_user_login(request, userprofile.user, email=form.cleaned_data.get('email'), password=form.cleaned_data.get('password'), next=form.cleaned_data.get('next')) else: form = RegistrationForm() return response(request, registration_template, {'form': form, 'next': next})
def UsersRegistration(request): if request.user.is_authenticated(): return HttpResponseRedirect('/main/profile') if request.method == 'POST': form = RegistrationForm(request.POST, request.FILES) if form.is_valid(): user = User.objects.create_user(username=form.cleaned_data['username'],email=form.cleaned_data['email'],password=form.cleaned_data['password']) user.save() new_user = Users(user=user, name=form.cleaned_data['name'], surname=form.cleaned_data['surname'],country = form.cleaned_data['country'],user_pic = form.cleaned_data['user_pic']) new_user.save() return HttpResponseRedirect('/main/profile/') else: return render_to_response('./main/register.html',{'form':form},context_instance=RequestContext(request)) else: form = RegistrationForm() context = {'form':form} return render_to_response('./main/register.html',context,context_instance=RequestContext(request))
def register_view(request): if request.user.is_authenticated: return HttpResponseRedirect(reverse('index')) if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): username = form.cleaned_data.get('username') password = form.cleaned_data.get('password1') user = User.objects.create_user(username=username, password=password) return HttpResponseRedirect(reverse('index')) else: return render(request, 'registration/register.html', {'form': form}) else: form = RegistrationForm() return render(request, 'registration/register.html', {'form': form})
def registration_view(request): context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() email = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password1') name = form.cleaned_data.get('first_name') account = authenticate(email=email, password=raw_password) login(request, account) profile = Userprofile.objects.create(user=request.user, username=name, email=email) profile.save() return redirect('home') else: context['registration_form'] = form else: #GET form = RegistrationForm() context['registration_form'] = form return render(request, 'users/register.html', context)
def register(request): # if request.user.is_authenticated(): # # They already have an account; don't let them register again # return render(request, 'users/register.html', {'has_account': True}) if request.POST: register_form = RegistrationForm(request.POST) if register_form.is_valid(): new_user = User.objects.create_user(register_form.data['username'], register_form.data['email'], register_form.data['password']) new_user.is_active = False new_user.save() # Build the activation key for their account salt = sha.new(str(random.random())).hexdigest()[:5] activation_key = sha.new(salt + new_user.username).hexdigest() key_expires = timezone.now() + datetime.timedelta(2) new_user.userprofile.activation_key = activation_key new_user.userprofile.key_expires = key_expires new_user.userprofile.save() # Send an email with the confirmation link email_subject = u'Neuer Nutzer bei Mi-Topo.de' email_body = u'Hallo, %s, Vielen Dank dass Sie sich entschieden haben Ihren Teil zu MiTopo beizutragen. \ Um Ihre Benutzerkennung zu aktivieren, klicken Sie bitte innerhalb der naechsten 2 Tage auf folgenden Link. \ \n\nhttp://%s/users/confirm/%s' % ( new_user.email, request.get_host(), new_user.userprofile.activation_key, ) send_mail(email_subject, email_body, '*****@*****.**', [ new_user.email, ]) return render(request, 'users/register.html', { 'register_successfully': True, 'form': register_form }) else: register_form = RegistrationForm() return render(request, 'users/register.html', {'form': register_form})
def home(request): if request.method == 'POST': form = RegistrationForm(request.POST, request.FILES) if form.is_valid(): form.save() new_user = authenticate( username=form.cleaned_data['username'], password=form.cleaned_data['password1'], ) login(request, new_user) profile_pic = form.cleaned_data['profile_pic'] print(f'profile pic {profile_pic} \n\n') if profile_pic is None or len(profile_pic) == 0: profile_pic = 'profile_pics/default.png' user = Profile.objects.create(user=new_user, problems_tried=0, problems_solved=0, problems_TLE=0, problems_WA=0, profile_pic=profile_pic) messages.success(request, "Thanks for registering.") # return redirect('profile') return redirect(reverse('home')) else: form = RegistrationForm() args = {'form': form} return render(request, 'homepage/homepage.html', args)
def register(request): form = RegistrationForm() if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') email = form.cleaned_data.get('email') messages.success(request,f'Account created for {username}!') messages.success(request,f'Account created for {email}!') return redirect('blog-home') else: form = RegistrationForm() return render(request,'users/masuk.html',{'form':form})
def register_view(request, *args, **kwargs): user = request.user if user.is_authenticated: return HttpResponse("Ya iniciaste sesión como " + str(user.email)) context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() email = form.cleaned_data.get('email').lower() date_of_birth = form.cleaned_data.get('date_of_birth') dni = form.cleaned_data.get('dni') raw_password = form.cleaned_data.get('password1') account = authenticate(email=email, password=raw_password) login(request, account) destination = get_redirect_if_exists(request) if destination: #if destination != None return redirect(destination) return redirect("Home") else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'users/register.html', context)
def register(request): if request.user.is_authenticated(): return HttpResponseRedirect('/') if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): user = User.objects.create_user( username=form.cleaned_data['username'], email=form.cleaned_data['email']) user.set_password(form.cleaned_data['password1']) user.profile.institute = form.cleaned_data['institute'] user.profile.institute = form.cleaned_data['course'] user.profile.save() user.save() return HttpResponseRedirect('/') else: form = RegistrationForm() return render(request, 'users/register.html', {'form': form})
def post(self, request): form = RegistrationForm(request.POST) if form.is_valid(): new_user = form.save() # TODO - crear el usuario y su blog en una sóla llamada blog_for_newUser = Blog() blog_for_newUser.owner = new_user blog_for_newUser.name = new_user.first_name + ' ' +new_user.last_name + '\'s Personal Blog' blog_for_newUser.save() return redirect(reverse('users_login')) else: context = { 'signup_form': form } return render(request, 'users/sign-up.html', context)
def UserbetRegistration(request): if request.user.is_authenticated(): return HttpResponseRedirect('/user/') if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): user = User.objects.create_user(username=form.cleaned_data['username'], email = form.cleaned_data['email'], password = form.cleaned_data['password']) user.save() userbet = Userbet(user=user, name=form.cleaned_data['name'], birthday=form.cleaned_data['birthday'],firstname=form.cleaned_data['firstname'], address=form.cleaned_data['address'],postcode=form.cleaned_data['postcode'], city=form.cleaned_data['city'],country=form.cleaned_data['country']) userbet.save() return HttpResponseRedirect('/user/') else: return render_to_response('users/register.html', {'form': form}, context_instance=RequestContext(request)) else: ''' user is not submitting the form, show them a blank registration form ''' form = RegistrationForm() context = {'form': form} return render_to_response('users/register.html', context, context_instance=RequestContext(request))