mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 18:52:23 +01:00
Disable registration and add study field to user model
This commit is contained in:
20
marietje/marietje/migrations/0005_user_study.py
Normal file
20
marietje/marietje/migrations/0005_user_study.py
Normal file
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-11-03 10:47
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('marietje', '0004_user_reset_token'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='study',
|
||||
field=models.CharField(blank=True, max_length=30, verbose_name='study'),
|
||||
),
|
||||
]
|
||||
@ -77,6 +77,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
'Unselect this instead of deleting accounts.'
|
||||
),
|
||||
)
|
||||
study = models.CharField(_('study'), max_length=30, blank=True)
|
||||
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
|
||||
|
||||
objects = UserManager()
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<a href="{% url 'register' %}" >Don't have an account? Register</a><br>
|
||||
Don't have an account? Send an email to {{ contact_email }}<br>
|
||||
<a href="{% url 'forgotpassword' %}" >Forgot your password? Reset password</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -3,37 +3,11 @@
|
||||
{% block title %}Register{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form method="POST" action="{% url 'register' %}">
|
||||
{% csrf_token %}
|
||||
<div class="row centered-form">
|
||||
<div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Register</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<input type="text" name="name" class="form-control input-sm" placeholder="Full Name">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<input name="email" type="text" class="form-control" placeholder="Email Address" aria-describedby="email-postfix">
|
||||
<span class="input-group-addon" id="email-postfix">@science.ru.nl</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<input type="password" name="password1" class="form-control input-sm" placeholder="Password">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<input type="password" name="password2" class="form-control input-sm" placeholder="Confirm Password">
|
||||
</div>
|
||||
<input type="submit" value="Register" class="btn btn-primary btn-block">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row centered-form">
|
||||
<div class="col-xs-12 col-sm-10 col-md-8 col-md-offset-2">
|
||||
<center>
|
||||
<strong>Registration by interface is disabled. To register an account, please send an email to {{ contact_email }} with your C&CZ username and the name of your study.</strong>
|
||||
</center>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@ -13,33 +13,7 @@ from .forms import RegistrationForm, ResetPasswordForm
|
||||
|
||||
|
||||
def register(request):
|
||||
if not request.POST:
|
||||
return render(request, 'registration/register.html')
|
||||
|
||||
form = RegistrationForm(request.POST)
|
||||
|
||||
if not form.is_valid():
|
||||
return render(request, 'registration/register.html', {'form': form})
|
||||
user = form.save(commit=False)
|
||||
|
||||
user.username = request.POST.get('email')
|
||||
user.email = user.username + '@science.ru.nl'
|
||||
user.name = request.POST.get('name')
|
||||
user.activation_token = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(32))
|
||||
user.queue = get_first_queue()
|
||||
user.save()
|
||||
|
||||
activation_link = request.build_absolute_uri(reverse('activate', args=[user.id, user.activation_token]))
|
||||
|
||||
send_mail('Marietje - Confirm your account',
|
||||
'Please confirm your account by following this link: ' + activation_link,
|
||||
settings.MAIL_FROM,
|
||||
[user.email],
|
||||
fail_silently=True)
|
||||
messages.add_message(request, messages.INFO, 'Please check your email, ' + user.email + ', for activation.',
|
||||
extra_tags='info')
|
||||
return redirect('login')
|
||||
|
||||
return render(request, 'registration/register.html')
|
||||
|
||||
def activate(request, user_id, token):
|
||||
User = get_user_model()
|
||||
|
||||
Reference in New Issue
Block a user