Skip to content

Commit

Permalink
login&registration
Browse files Browse the repository at this point in the history
login works
need to continue work on registration
  • Loading branch information
nishi7409 committed Dec 28, 2020
1 parent 7266810 commit b193490
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 59 deletions.
Binary file modified web_app/app/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file modified web_app/app/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file modified web_app/app/__pycache__/views.cpython-36.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion web_app/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ class University(models.Model):
registeredStudents = models.IntegerField(null=False, blank=False)

class Student(models.Model):
email = models.CharField(max_length=100, null=False, blank=False)
name = models.CharField(max_length=100, null=False, blank=False)
email = models.CharField(max_length=100, null=False, blank=False)
phone_num = models.CharField(max_length=200, null=False, blank=False)
status = models.IntegerField(null=False, blank=False)
calendar_link = models.ForeignKey("URLCalendar", on_delete=models.CASCADE)

class URLCalendar(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion web_app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
urlpatterns = [
path('', views.index, name='home'),
path('signup', views.signUp, name='signup'),
path('login', views.signUp, name='login'),
path('login', views.userLogin, name='login'),
]
62 changes: 52 additions & 10 deletions web_app/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,70 @@ def index(request):

# sign up page
def signUp(request):
if request.method == "POST":
name = request.post['name']
email = request.post['email']
phoneNum = request.post['phoneNum']

form = UserForm(data = request.POST)

if form.is_valid():
user = form.save()

user.is_active = False
user.save()

uniqueURL = URLCalendar(calendar=urlGenerator.createURL())
newStudent = Student(name=name, email=email, phone_num=phoneNum, status=False, calendar_link=uniqueURL)
newStudent.save()

html_msg = f"<p><a href='{request.build_absolute_uri('/register/confirm/')}{user.id}'>Click here to activate your account!</a></p>"
mail.send_mail("Account Confirmation", "Please confirm your account registration.", settings.EMAIL_HOST_USER, [user.email], html_message=html_msg)
else:
pass
else:
form = UserCreationForm()
return render(request, 'sign-up.html', {})

# sign up page
def userLogin(request):
if request.method == "POST":
username = request.POST['username']
password = request.POST['password']

user = authenticate(username=username, password=password)

# valid user
if user:
# user is valid, active, and authenticated
if user.is_active:
login(request, user)
request.session['is_login'] = True
request.session['user_name'] = username
# user_id = User.objects.filter(username = username).values('id').first()
# request.session['user_id'] = user_id['id']
return render(request, 'dashboard.html', {'error': 'Success and account is activated'})

# user is valid, but not active
else:
return render(request, 'login.html', {'error': 'Success, but account is deactivated'})

# user doesn't exist
else:
return render(request, 'login.html', {'error': 'Invalid login credentials'})

return render(request, 'login.html', {})

def save_university(request):
if request.method == "POST":
newUni = University(name="Rensselaer Polytechnic Institute", domain="rpi.edu", registeredStudents=0)
newUni.save()
else:
pass

def save_student(request):
if request.method == "POST":
uniqueURL = URLCalendar(calendar=urlGenerator.createURL())
newStud = Student(name="Nishant Srivastava", email="[email protected]", phone_num=5186182796, calendar_link=uniqueURL)
newStud.save()
else:
pass

def register(request):
pass

def login(request):
pass

def otp():
pass
Binary file modified web_app/mydatabase
Binary file not shown.
54 changes: 31 additions & 23 deletions web_app/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,35 @@
<!-- put main code here -->
{% block content %}

<div class="card">
<div class="card-content">
<p class="title">
"Life is a journey"
</p>
<p class="subtitle">
Dad
</p>
</div>
<footer class="card-footer">
<p class="card-footer-item">
<span>
View on <a href="https://twitter.com/codinghorror/status/506010907021828096">Twitter</a>
</span>
</p>
<p class="card-footer-item">
<span>
Share on <a href="#">Facebook</a>
</span>
</p>
</footer>
</div>

<center>
<form method="POST" action="login">
{% csrf_token %}
<div class="field" style="width:50%;">
<fieldset class="form-group">
<label class="label">Username</label>
<div class="control">
<input id="username" name="username" class="input" type="username" placeholder="username"/>
</div>
</fieldset>
<fieldset class="form-group">
<label class="label">Password</label>
<div class="control">
<input id="password" name="password" class="input" type="password" placeholder="********"/>
</div>
</fieldset>
{% if error %}
<br>
<div class="notification is-danger"r">
<strong>{{ error|escape }}</strong>
</div>
{% endif %}
<br>
<div class="control">
<button type="submit" id="loginButton" class="button is-success">Login</button>
</div>
<br>
<a href="{% url 'signup' %}" style="color: blue;">Don't have an account? Sign up here!</a>
</div>
</form>
</center>
{% endblock %}
4 changes: 2 additions & 2 deletions web_app/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<div class="navbar-item">
<div class="buttons">
<a class="button is-danger" href="signup">
<strong>Sign up</strong>
<strong>Sign Up</strong>
</a>
<a class="button is-success" href="login">
Log in
<strong>Login</strong>
</a>
</div>
</div>
Expand Down
52 changes: 31 additions & 21 deletions web_app/templates/sign-up.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,37 @@
<!-- put main code here -->
{% block content %}

<div class="card">
<div class="card-content">
<p class="title">
“There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors.”
</p>
<p class="subtitle">
Jeff Atwood
</p>
<center>
<div class="field" style="width:50%;">
<label class="label">Name</label>
<div class="control">
<input class="input" type="text" placeholder="John Doe">
</div>
<br>
<label class="label">Email</label>
<div class="control">
<input class="input" type="email" placeholder="[email protected]">
</div>
<br>
<label class="label">Password</label>
<div class="control">
<input class="input" type="password" placeholder="*********">
</div>
<br>
<label class="label">Retype Password</label>
<div class="control">
<input class="input" type="password" placeholder="*********">
</div>
<br>
<label class="label">Phone Number</label>
<div class="control">
<input class="input" type="number" placeholder="123-456-7890">
</div>
<br>
<div class="control">
<button id="signUpButton" class="button is-danger">Sign Up</button>
</div>
</div>
<footer class="card-footer">
<p class="card-footer-item">
<span>
View on <a href="https://twitter.com/codinghorror/status/506010907021828096">Twitter</a>
</span>
</p>
<p class="card-footer-item">
<span>
Share on <a href="#">Facebook</a>
</span>
</p>
</footer>
</div>
</center>

{% endblock %}
Binary file modified web_app/web_app/__pycache__/settings.cpython-36.pyc
Binary file not shown.
12 changes: 11 additions & 1 deletion web_app/web_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@

USE_TZ = True

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
# Host email ([email protected])
EMAIL_HOST_USER = '[email protected]'
# Host email password
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_PASSWORD")
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
Expand All @@ -126,4 +136,4 @@

STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static/'),
)
)

0 comments on commit b193490

Please sign in to comment.