Пример #1
0
 def post(self, request):
     form = SignUpForm(request.POST)
     if not form.is_valid():
         return render(request, 'accounts/register.html', {'form':form})
     username = form.cleaned_data['username']
     password = form.cleaned_data['password']
     user = User.objects.create_user(username = username, password = password)
     return render(request, 'accounts/register-ok.html', {'user':user})
Пример #2
0
def sign_up(request):
    if request.method == "POST":
        form = SignUpForm(request.POST)
        if form.is_valid():
            user_profile = UserProfile.objects.sign_up(form.cleaned_data["username"], form.cleaned_data["password"])
            login(request, user_profile.user)
            return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
    else:
        form = SignUpForm()

    c = dict(form=form)
    return render_to_response("accounts/sign_up.html", c, context_instance=RequestContext(request))
Пример #3
0
def signup(request):
    if request.method == 'POST':
        # ipdb.set_trace()
        form = SignUpForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']

            new_user = User.objects.create_user(username, email, password)
            new_user.first_name = form.cleaned_data['first_name']
            new_user.last_name = form.cleaned_data['last_name']
            new_user.save()
            new_user = authenticate(username=username, password=password)
            login(request, new_user)
            return redirect('books:user_books', username=username)
    else:
        form = SignUpForm()
    return render(request, 'accounts/signup_in.html', {'signup_in_form': form})
Пример #4
0
def cm_useradd(request, *args, **kargs):
    """create a new user"""

    from hashlib import md5
    form = SignUpForm(request.POST)
    if form.is_valid():
        user = \
            User.objects.create_user(username=md5(str(form.cleaned_data['email'
                ])).hexdigest()[:30],
                password=form.cleaned_data['password'],
                email=form.cleaned_data['email'])
        user.last_name = form.cleaned_data['last']
        user.first_name = form.cleaned_data['first']
        user.save()
        profile = UserProfile(user=user,
                              institute=form.cleaned_data['institute'])
        profile.save()
        request.user.message_set.create(message='Your account has been created. Please log in.'
                )
        return HttpResponseRedirect(request.get_full_path())
    else:
        return dict(form_signup=form)
Пример #5
0
def signup(request):
    invited_by = None
    if request.method == 'GET':
        invited_by_id = request.GET.get('invited_by', None)
        form = SignUpForm()
    elif request.method == 'POST':
        form = SignUpForm(request.POST)
        invited_by_id = request.POST.get('invited_by', None)
        if form.is_valid():
            if invited_by_id:
                try:
                    invited_by = Account.objects.get(pk=invited_by_id)
                except Account.DoesNotExist:
                    pass
            new_account = Account.objects.create_user(
                form.cleaned_data['email'],
                password=form.cleaned_data['password'],
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
                invited_by=invited_by
            )
            new_user = authenticate(email=request.POST['email'],
                                    password=request.POST['password'])
            request.session['account_id'] = new_account.id
            login(request, new_user)
            return HttpResponseRedirect('/dashboard/')
    if invited_by_id:
        try:
            invited_by_obj = Account.objects.get(pk=invited_by_id)
        except Account.DoesNotExist:
            pass
        else:
            invited_by = {
                'user_id': invited_by_obj.id,
                'full_name': invited_by_obj.first_name + ' ' + invited_by_obj.last_name
            }
    return render(request, 'signup.html', {'form': form, 'invited_by': invited_by})
Пример #6
0
def signup(request):
	user_form = SignUpForm(data=request.POST)
	if request.method == "POST":
		if user_form.is_valid():
			username = user_form.clean_username()
			password = user_form.clean_password2()
			user_form.save()
			user = authenticate(username=username, password=password)
			login(request, user)
			return redirect('/about-create')
		else:
			return index(request, user_form=user_form)
	return redirect('/about-create')
Пример #7
0
def signup(request):
    form = SignUpForm(request.POST or None)
    if form.is_valid():

        first_name = form.cleaned_data['first_name']
        last_name = form.cleaned_data['last_name']
        username = form.cleaned_data['username']
        email = form.cleaned_data['email']
        password = form.cleaned_data['password']

        user_obj = User.objects.create(
            first_name=first_name.title(),
            last_name=last_name.title(),
            username=username,
            email=email,
            date_joined=datetime.datetime.now(),
            is_active=False,
            password=make_password(password),
            is_superuser=False,
            is_staff=False,
        )

        profile = Profile(user=user_obj,
                          dob=form.cleaned_data['dob'],
                          sex=form.cleaned_data['sex'],
                          last_edited_on=datetime.datetime.now(),
                          )
        profile.save()

        PrivacySettings.objects.create(user=user_obj,
                                       friends_visibility='F',
                                       cover_photos_visibility='F',
                                       profile_photos_visibility='F',
                                       daily_photos_visibility='F',
                                       stories_visibility='F',
                                       calendar_visibility='F',
                                       )
        ProfilePhoto.objects.create(user=user_obj,
                                    profile_photo='profile_photo/default_avatar.jpg',
                                    cropping='',
                                    is_set=True,
                                    key='123456789',
                                    uploaded_on=datetime.datetime.now())

        # Sending the confirmation email here.
        try:
            ACTIVATION_KEY = activation_key_generator(20,
                                                      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdegfhijklmnopqrstuvwxyz1234567890")
            subject = 'Oposod.com: User %s creation information.' % (username)
            html_content = '''<div style="border: 1px solid #ddd; background: #000; padding: 30px; font-size: 50px; font-family: 'Ubuntu'">
                            <p>Hello %s . You have successfully registered your account on oposod.com
                            . To proceed further, you need to verfiy your email id.</p>
                            <p>Please follow this link %s/account/activation/%s</p>
                            </div>''' % (username, SITE, ACTIVATION_KEY)
            recipient_list = [email]

            send_html_mail(subject, html_content, recipient_list)

            rp = RegistrationProfile(user=user_obj, activation_key=ACTIVATION_KEY)
            rp.save()

        except Exception, e:
            return render(request, '404_error.html', {
                'msg': 'There is some error in sending the email. The error is: %s' % e
            })

        messages.info(request,
                      'You have successfully registered, please activate your account from your email before signing in.')
        return HttpResponseRedirect(reverse('signin'))