Example #1
0
def ajax_register(request):
    """ AJAX regsiter procedure """
    if request.method != 'POST':
        return HttpResponse("NOTFOUND")

    reg_form = RegistrationForm(request.POST)
    if reg_form.is_valid():
        username = reg_form.cleaned_data['username']
        email = reg_form.cleaned_data['email']
        password = reg_form.cleaned_data['password']
        user_type = reg_form.cleaned_data['user_type']
        if User.objects.filter(
                username=username).exists() or User.objects.filter(
                    email=email).exists():
            #checking for existing emails and usernames
            return HttpResponse("EXISTS")
        user = User.objects.create_user(username, email, password)
        user_profile = UserProfile(account=user, user_type=user_type)

        user.save()
        user_profile.save()

        return HttpResponse("OK")
    else:
        return HttpResponse("NOTVALID")
Example #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('views.dashboard'))
    form = RegistrationForm(request.form)
    if request.method == "POST" and form.validate():
        check_username = User.query.filter_by(
            username=form.username.data).first()
        check_email = User.query.filter_by(username=form.email.data).first()
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        if check_username:
            flash(f'That username is taken. Please choose a different one.',
                  'danger')
            return render_template('register.html', form=form)
        elif check_email:
            flash(f'That email is taken. Please choose a different one.',
                  'danger')
            return render_template('register.html', form=form)
        else:
            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'Account created for {form.username.data}!', 'success')
            return redirect(url_for('auth.login'))

    return render_template('register.html', form=form)
Example #3
0
def new_registration(request):
    if request.method == "POST":
        regForm = RegistrationForm(request.POST)

        if not regForm.is_valid():
            return render(request, 'website/register.html', {'form': RegistrationForm().as_ul(), 'error': regForm.errors})

        try:
            username = request.POST['username']
            password = request.POST['password']
            email = request.POST['email']
        except KeyError:
            return HttpResponse("Invalid input.")

        userExists = True if len(User.objects.filter(username=username)) == 1 else False
        emailExists = True if len(User.objects.filter(email=email)) == 1 else False

        if userExists:
            return HttpResponse("Username already taken.")
        if emailExists:
            return HttpResponse("Email already registered.")

        try:
            User.objects.create_user(username, email, password)
        except:
            return HttpResponse("Error adding user.")

        user = authenticate(username=username, password=password)
        return login(request, user=user)
      
    if request.method == "GET":
        return render(request, 'website/register.html', {'form': RegistrationForm().as_ul()})
Example #4
0
File: auth.py Project: OReznyk/MHA
def signup():
    if current_user.is_authenticated:
        flash('בבקשה תתנתקו לצורך רישום משתמש חדש', 'error')
        return redirect(url_for("views.dashboard"))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pwd = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        # TODO: check permissions: create regular user for all types of permissions
        # if not regular permission ->  flash msg as: user created & send for permission approval
        user = User(email=form.email.data, first_name=form.firstname.data,
                        second_name=form.name.data, birth_date=form.birthdate.data, password=hashed_pwd)
        if form.permissions.data == "נחקר":
            user.permission_confirmation = True
        # Saving user to db
        db.session.add(user)
        g = db.session.query(Gender).filter_by(gender=form.gender.data).first()
        p = Permissions.query.filter_by(permission=form.permissions.data).first()
        g.users.append(user)
        p.users.append(user)
        db.session.commit()
        flash('משתמש נוצר בהצלחה', 'success')
        # TODO: send email verificathion if needed
        # TODO: redirect to verification page/popup?
        return redirect(url_for("auth.login"))

    return render_template('signup.html', form=form)
Example #5
0
def registration_open(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            new_registration = form.save()
            return render(request, 'website/registration_confirm.htm',
                          {'form': form})
    else:
        form = RegistrationForm()
    return render(request, 'website/registration_open.htm',
                  {'form': form})
Example #6
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('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('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Example #7
0
def register():
  form = RegistrationForm()
  if not form.validate():
    flash(u"Veuillez corriger les erreurs ci-dessous.", "error")
    return render_template("registration_fr.html", form=form)
  else:
    registration = Registration()
    form.populate_obj(registration)
    db.session.add(registration)
    db.session.commit()
    flash(u"Votre inscription a bien été prise en compte.", "success")
    return redirect(url_for("home"))
Example #8
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Example #9
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    registration_form = RegistrationForm()
    if registration_form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            registration_form.password.data).decode('UTF-8')
        new_user = User(username=registration_form.username.data,
                        email=registration_form.email.data,
                        password=hashed_password)
        db.session.add(new_user)
        db.session.commit()
        return redirect(url_for('login'))
    return render_template('sign-up-page.html', form=registration_form)
Example #10
0
def registration_view(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if not User.objects.filter(username=request.POST['username']).exists():
            user = form.save()
            user.set_password(request.POST['password'])
            user.save()
            login(request, user)
            return HttpResponseRedirect(reverse('post_list'))
        else:
            messages.add_message(request, messages.ERROR,
                                 'Username is already taken')
            return HttpResponseRedirect(request.META.get('HTTP_REFERER', None))
    else:
        form = RegistrationForm()
        return render(request, 'registration/registration_form.html',
                      {'form': form})
Example #11
0
def registration(request, event_id, slug):
    """
    Render and show event registration form to the user. The registration form allows students
    to register interest for a particular event.

    Args:
        request: HTTP request header contents
        event_id: the unique ID of the event
        slug: the human-readable event name in the URL

    Returns:
        HTTP response containing the registration form for the given event
    """
    event = get_object_or_404(Event, pk=event_id)
    # redirect to correct url if needed
    if event.slug != slug:
        return redirect('website:registration',
                        event_id=event.pk,
                        slug=event.slug)

    if request.method == 'POST':
        registration_form = RegistrationForm(request.POST)
        if registration_form.is_valid():
            registration_form.save()
            return redirect('website:event_index')
    else:
        registration_form = RegistrationForm()
        registration_form.fields['event'].initial = event

    context = {'registration_form': registration_form, 'event': event}
    return render(request, 'website/registration_form.html', context)
Example #12
0
def register():
    print(count)
    if current_user.is_authenticated:
        flash(
            'You are already logged in. Please log out to create a new account.',
            'danger')
        return redirect(url_for('home'))
    form = RegistrationForm()
    title = 'Register'
    if form.validate_on_submit():
        #Generate a hashed-password, and store user + hashed pw in db
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = user_list(username=form.username.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(
            'Account created successfully. You can now log in with your username and password.',
            'success')
        return redirect(url_for('login'))
    return render_template('register.html', title=title, form=form)
Example #13
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/marketday/login')

    else:
        form = RegistrationForm()
        args = {'form': form}
        return render(request, 'website/reg_form.html', args)
Example #14
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("home"))
    form = RegistrationForm()
    if form.validate_on_submit():
        users = getDBData()
        userFoundRow = None
        if users:
            for row in users:
                if row.username.lower() == form.username.data.lower():
                    userFoundRow = row
                    break

        if not userFoundRow:
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode("utf-8")

            addUser(form.username.data, hashed_password)
            flash("User successfully created!")
            return redirect(url_for("login"))
        flash("The specified household nickname already exists")
    return render_template("register.html", form=form)
Example #15
0
def register():
    context = global_context()
    if current_user:
        if current_user.is_authenticated:
            return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        email = form.email.data
        token = serializer.dumps(email, salt='email-confirmation')
        confirmation_link = url_for('confirm_email',
                                    token=token,
                                    _external=True)
        user_data = {
            'firstname': form.firstname.data,
            'lastname': form.lastname.data,
            'email': form.email.data,
            'password': hashed_password,
            'confirmation_link': confirmation_link,
        }
        user = User(**user_data)
        msg = Message('NBDF Anmeldung - Email bestätigen',
                      sender=app.config['MAIL_USERNAME'],
                      recipients=[email])
        msg.body = f'Willkommen auf der NBDF Seite.\n\nBitte benutze diesen Link um deinen Account zu bestätigen: {confirmation_link.replace("localhost",server_IP)}\n\nBitte antworte nicht direkt auf diese Email.'
        mail.send(msg)
        db.session.add(user)
        db.session.commit()
        flash(
            f'Willkommen {form.firstname.data}, bitte bestätige die Email für deinen Account.',
            'success')
        #context['user_email'] = form.email.data
        return redirect(url_for('login', **context))
    context['form'] = form
    context['title'] = 'Registrieren'
    return render_template('register.html', **context)
Example #16
0
def signup(request):

    if request.method == "POST":

        User.objects.create_user(username=request.POST.get('username'),
                                 password=request.POST.get('password'),
                                 email=request.POST.get('mail'),
                                 first_name=request.POST.get('first_name'),
                                 last_name=request.POST.get('last_name'))

        return redirect("/")

    context = {'title': "Inscrivez-vous", 'form': RegistrationForm()}

    return render(request, "signup.html", context)
Example #17
0
def account(request):

    user = request.user

    user_data = {
        'username': user.username,
        'first_name': user.first_name,
        'last_name': user.last_name,
        'mail': user.email
    }

    context = {
        'title': "Mon compte",
        'form': RegistrationForm(initial=user_data)
    }

    return render(request, "account.html", context)
Example #18
0
def index(request):
    """ View on main page / """
    if request.user.is_authenticated() is False:
        reg_form = RegistrationForm(auto_id='reg_%s')
        login_form = LoginForm(auto_id='login_%s')

        c = {
            'reg_form': reg_form,
            'login_form': login_form,
            'session': request.user
        }
        c.update(csrf(request))

        return render_to_response('index.html',
                                  c,
                                  context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect("/profile/")
Example #19
0
def registration(request):
    """Page to create an account"""
    if request.method == 'POST':
        form = RegistrationForm(request.POST)

        if form.is_valid():
            form.save()
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                return redirect('home')
    else:
        form = RegistrationForm()
    context = {'form' : form}
    return render(request, 'pages/registration.html', context)
Example #20
0
def user_registration(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, 'successfully user created')

            return HttpResponseRedirect(reverse('user-registration'))
        else:
            form.errors
            messages.error(request, 'Enter data properly')

    else:
        form = RegistrationForm()

        context = {'form': form}

        return render(request, "register.html", context)
Example #21
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        flash(f'Account Created for {form.username.data}!', 'success')
        return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form)
Example #22
0
def register(request):
    if request.method == 'POST':

        registration_form = RegistrationForm(request.POST)

        if registration_form.is_valid():
            username = registration_form.cleaned_data['username']
            password = registration_form.cleaned_data['password']
            password_confirmation = registration_form.cleaned_data['password_confirmation']
            email = registration_form.cleaned_data['email']
            first_name = registration_form.cleaned_data['first_name']
            last_name = registration_form.cleaned_data['last_name']
            lives_motto = registration_form.cleaned_data['lives_motto']

            new_user = User(username=username, password=password, email=email, first_name=first_name, last_name=last_name)
            new_user.save()

            new_person = Person(user=new_user, lives_motto=lives_motto)
            new_person.save()

            default_data = {
                'username': username,
                'password': password,
                'password_confirmation': password_confirmation,
                'email': email,
                'first_name': first_name,
                'last_name': last_name,
                'lives_motto': lives_motto,
            }

            context = {
                'registration_form': RegistrationForm(default_data, auto_id=False),
                'success': 1,
            }

            return render(request, 'registration/register.html', context)
        else:
            username = request.POST.get('username', '')
            password = request.POST.get('password','')
            password_confirmation = request.POST.get('password_confirmation', '')
            email = request.POST.get('email', '')
            first_name = request.POST.get('first_name', '')
            last_name = request.POST.get('last_name', '')
            lives_motto = request.POST.get('lives_motto', '')

            default_data = {
                'username': username,
                'password': password,
                'password_confirmation': password_confirmation,
                'email': email,
                'first_name': first_name,
                'last_name': last_name,
                'lives_motto': lives_motto,
            }

            context = {
                'registration_form': RegistrationForm(default_data, auto_id=False),
                'registration_form_errors': registration_form.errors,
                'success': 2,
            }
            return render(request, 'registration/register.html', context)
    else:
        context = {
            'registration_form': RegistrationForm(),
            'success': 0,
        }
        return render(request, 'registration/register.html', context)