예제 #1
0
def register(request):
    if request.method == "POST":

        class RegisterError:
            pass

        try:
            form = RegistrationForm(request.POST)
            if not form.is_valid():
                error_header = "That's not quite right."
                raise RegisterError()

            if len(User.objects.filter(email=form.cleaned_data["email"])) is not 0:
                error_header = "That email is already registered."
                raise RegisterError()

            if form.cleaned_data["password"] != request.POST["password_confirm"]:
                error_header = "Your passwords didn't match."
                raise RegisterError()

            # validate the captcha is recaptcha is enabled
            if RECAPTCHA_PUBLIC is not None:
                capt = captcha.submit(
                    request.POST["recaptcha_challenge_field"],
                    request.POST["recaptcha_response_field"],
                    RECAPTCHA_PRIVATE,
                    request.META["REMOTE_ADDR"],
                )
                if not capt.is_valid:
                    error_header = "Let's try that captcha again."
                    raise RegisterError()

            resp = create_user(request, form)
            return resp
        except RegisterError:
            pass

    # GET
    else:
        error_header = None
        form = RegistrationForm()

    return render_to_response(
        "users/register.html",
        {
            "next": reverse(feed.main),
            "reg_form": form,
            "error_header": error_header,
            "RECAPTCHA_PUBLIC": RECAPTCHA_PUBLIC,
            "RECAPTCHA_PRIVATE": RECAPTCHA_PRIVATE,
        },
        context_instance=RequestContext(request),
    )
예제 #2
0
def register(request):
    if request.method == "POST":

        class RegisterError:
            pass

        try:
            form = RegistrationForm(request.POST)
            if not form.is_valid():
                error_header = "That's not quite right."
                raise RegisterError()

            if len(User.objects.filter(
                    email=form.cleaned_data["email"])) is not 0:
                error_header = "That email is already registered."
                raise RegisterError()

            if form.cleaned_data['password'] != request.POST[
                    'password_confirm']:
                error_header = "Your passwords didn't match."
                raise RegisterError()

            # validate the captcha is recaptcha is enabled
            if RECAPTCHA_PUBLIC is not None:
                capt = captcha.submit(
                    request.POST["recaptcha_challenge_field"],
                    request.POST["recaptcha_response_field"],
                    RECAPTCHA_PRIVATE, request.META["REMOTE_ADDR"])
                if not capt.is_valid:
                    error_header = "Let's try that captcha again."
                    raise RegisterError()

            resp = create_user(request, form)
            return resp
        except RegisterError:
            pass

    # GET
    else:
        error_header = None
        form = RegistrationForm()

    return render_to_response('users/register.html', {
        'next': reverse(projects.list),
        'reg_form': form,
        'error_header': error_header,
        'RECAPTCHA_PUBLIC': RECAPTCHA_PUBLIC,
        'RECAPTCHA_PRIVATE': RECAPTCHA_PRIVATE
    },
                              context_instance=RequestContext(request))
예제 #3
0
def register(request):
    if request.method =='POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('login')
            
    else:
        form = RegistrationForm()

    args = {'form': form}
    return render(request, 'register.html', args)
예제 #4
0
def login_or_reg(request):
  next = reverse(projects.list)
  
  if 'next' in request.GET:
    next = request.GET['next']
  
  reg_form = RegistrationForm(auto_id = "id_login_%s")
  login_form = LoginForm(auto_id = "id_login_%s")
  
  return render_to_response('users/login-register.html', {
      'next': next,
      'js_page_id': 'login-register',
      'reg_form': reg_form,
      'login_form': login_form,
      'RECAPTCHA_PUBLIC': RECAPTCHA_PUBLIC,
      'RECAPTCHA_PRIVATE': RECAPTCHA_PRIVATE
    }, context_instance = RequestContext(request))
예제 #5
0
def signup_page(name=None):
    form = RegistrationForm(request.form,
                            captcha={'ip_address': request.environ.get('HTTP_X_REAL_IP',
                                                                       request.remote_addr)})
    if name is None:
        abort(404)
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    if request.method == 'POST':
        if name is None:
            abort(404)
        if form.validate_on_submit():
            query = User.query.filter_by(is_reseller=True, username=name).first_or_404()
            email = form.email.data
            restrict_email = email.split('@')
            if restrict_email[1] == 'gmail.com' or restrict_email[1] == 'yahoo.com':
                registered_email = User.query.filter_by(email=form.email.data).first()
                registered_user = User.query.filter_by(username=form.username.data).first()
                if registered_user is None and registered_email is None:
                    verification_code = email_key_generator()
                    msg = Message('SafeCore Identity Confirmation',
                                  recipients=[form.email.data]
                                  )
                    msg.html = render_template('email.html',
                                               email=form.email.data,
                                               confirmation=verification_code)
                    mail.send(msg)
                    query = User(
                        form.first_name.data,
                        form.last_name.data,
                        form.email.data,
                        form.username.data,
                        form.password.data,
                        query.username
                    )

                    email_expiration = datetime.now() + timedelta(days=1)
                    email_verify = Email(user=query,
                                         confirmation_key=verification_code,
                                         registration_date=datetime.now(),
                                         valid=True,
                                         expiration_date=email_expiration
                                         )
                    notify = Notifications(user_id=query.id, notification_type='signup', confirmed_date=datetime.now(),
                                           notification_ip=request.environ.get('HTTP_X_REAL_IP',
                                                                               request.remote_addr))

                    db.session.add(query, email_verify, notify)
                    db.session.commit()
                    flash('Please check your email for verification!', 'info')
                    return redirect(url_for('login'))
                else:
                    flash('Username or email already exists!', 'warning')
                    return redirect(url_for('reseller.signup_page'))
            else:
                flash('We only accept email in Google and Yahoo', 'warning')
                return redirect(url_for('reseller.signup_page'))
        else:
            flash('Something went wrong! Please check your form and try again', 'warning')
            return redirect(url_for('reseller.signup_page'))
    form = RegistrationForm(request.form,
                            captcha={'ip_address': request.environ.get('HTTP_X_REAL_IP',
                                                                       request.remote_addr)})
    query = User.query.filter_by(is_reseller=True, username=name).first_or_404()
    if query.account_status == 'banned' or query.account_status == 'deactivated':
        abort(404)
    else:
        return render_template('my_page_signup.html', query=User.query.filter_by(is_reseller=True, username=name).first_or_404(), form=form, page_title='Register under ' + query.username)