Skip to content

Commit 28e89e5

Browse files
author
Jonathan
committed
Django projects
1 parent 1fe6ea3 commit 28e89e5

File tree

206 files changed

+2538
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+2538
-0
lines changed

Beltexam3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 8e99f68f8f9f7e2a244eab0969b60a4dce760b46

Final_Login_Registration/apps/__init__.py

Whitespace-only changes.
184 Bytes
Binary file not shown.

Final_Login_Registration/apps/loginreg/__init__.py

Whitespace-only changes.
193 Bytes
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
250 Bytes
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from __future__ import unicode_literals
2+
3+
from django.apps import AppConfig
4+
5+
6+
class LoginregConfig(AppConfig):
7+
name = 'loginreg'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.10 on 2018-01-04 23:38
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
initial = True
11+
12+
dependencies = [
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='User',
18+
fields=[
19+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('name', models.CharField(max_length=255)),
21+
('alias', models.CharField(max_length=255)),
22+
('email', models.CharField(max_length=255)),
23+
('password', models.CharField(max_length=255)),
24+
('dob', models.DateTimeField()),
25+
('created_at', models.DateTimeField(auto_now_add=True)),
26+
('updated_at', models.DateTimeField(auto_now=True)),
27+
],
28+
),
29+
]
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.10 on 2018-01-05 18:46
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('loginreg', '0001_initial'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='user',
17+
name='dob',
18+
field=models.DateField(),
19+
),
20+
]
Binary file not shown.

Final_Login_Registration/apps/loginreg/migrations/__init__.py

Whitespace-only changes.
Binary file not shown.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
from __future__ import unicode_literals
2+
from django.db import models
3+
import re
4+
import bcrypt
5+
from datetime import datetime
6+
EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$')
7+
8+
class UserManager(models.Manager):
9+
10+
def validateUser(self, name, alias, email, password, password_confirm, dob):
11+
errors = []
12+
13+
if len(name) < 1:
14+
errors.append("Name is required")
15+
elif len(name) < 1:
16+
errors.append("Name must be longer than 3 char")
17+
18+
19+
if len(alias) < 1:
20+
errors.append("Alias is required")
21+
elif len(alias) < 3:
22+
errors.append("Alias must be longer than 3 char")
23+
24+
25+
if len(email) < 1:
26+
errors.append("Email is required")
27+
elif not EMAIL_REGEX.match(email):
28+
errors.append("invalid email")
29+
else:
30+
user = User.objects.filter(email=email.lower())
31+
if len(user)> 0:
32+
errors.append("Email already in use")
33+
34+
35+
if len(password) < 1:
36+
errors.append("Password is required")
37+
elif len(password) < 8:
38+
errors.append("Password must be longer than 8 char")
39+
40+
41+
if len(password_confirm) < 1:
42+
errors.append("Confirm password is required")
43+
elif password_confirm != password:
44+
errors.append("Password and Confirm Password must match")
45+
46+
47+
if len(dob) < 1:
48+
errors.append("dob is required")
49+
elif str(dob) > str(datetime.now()):
50+
errors.append("Birthday must be in the past!")
51+
52+
if len(errors)> 0:
53+
print errors
54+
return (False, errors)
55+
else :
56+
user = User.objects.create(name=name, alias=alias, email=email.lower(), password=bcrypt.hashpw(password.encode(), bcrypt.gensalt()), dob=dob)
57+
return (True,user)
58+
59+
def validateLogin(self, login_email, login_password):
60+
errors = []
61+
if len(login_email) < 1:
62+
errors.append("Email is required")
63+
elif not EMAIL_REGEX.match(login_email):
64+
errors.append('Email is invalid')
65+
66+
if len(login_password) < 1:
67+
errors.append('Password is required')
68+
else:
69+
user = User.objects.filter(email=login_email.lower())
70+
if len(user) == 0:
71+
errors.append("Email is not found in database")
72+
else:
73+
74+
print user # <QuerySet [<User: User object>]> this is a valid user print
75+
print user[0] # User object
76+
if bcrypt.checkpw(login_password.encode(), user[0].password.encode()):
77+
return (True, user[0])
78+
else:
79+
errors.append('Password is incorrect')
80+
if len(errors) > 0:
81+
print
82+
return (False, errors)
83+
84+
85+
86+
class User(models.Model):
87+
name = models.CharField(max_length=255)
88+
alias = models.CharField(max_length=255)
89+
email = models.CharField(max_length=255)
90+
password = models.CharField(max_length=255)
91+
dob = models.DateField(auto_now=False, auto_now_add=False)
92+
created_at = models.DateTimeField(auto_now_add=True)
93+
updated_at = models.DateTimeField(auto_now=True)
94+
objects = UserManager()
95+
96+
# class Quote(models.Model):
97+
# quoted_by = models.CharField(max_length=255)
98+
# quote = models.CharField(max_length=2000)
99+
# posted_by =
100+
# quote_follows =
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<h1>Welcome, {{ request.session.user_name }}! </h1>
11+
{{ request.session.user_id }}
12+
13+
<h2> Quoteable Quotes</h2>
14+
15+
<h2>Your Favorite Quotes</h2>
16+
17+
<div>
18+
<h3> Contribute a Quote:</h3>
19+
<form action="/user_quote" method="post"></form>
20+
Quoted By:
21+
<input type="text" name="quoted_by">
22+
Message:
23+
<input type="text" name="message" >
24+
</div>
25+
</body>
26+
</html>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>Quotes</title>
9+
</head>
10+
11+
<body>
12+
<h1>Welcome!</h1>
13+
<h3>Register</h3>
14+
<!--lets do registration first because we can just tweak it to do a login later-->
15+
16+
<form action="/user_register" method="post">
17+
{% csrf_token %}
18+
<p>Name:
19+
<input type="text" name="name" placeholder="Name">
20+
</p>
21+
<p>Alias:
22+
<input type="text" name="alias" placeholder="Alias">
23+
</p>
24+
<p>Email:
25+
<input type="text" name="email" placeholder="Email Address">
26+
</p>
27+
<p>Password:
28+
<input type="password" name="password" placeholder="Password">
29+
</p>
30+
<p>Confirm PW:
31+
<input type="password" name="confirm_password" placeholder="Confirm Password">
32+
</p>
33+
<p>Date of Birth:
34+
<input type="date" name="birthday">
35+
</p>
36+
<input type="submit" value="Register">
37+
</form>
38+
39+
<h3>Login</h3>
40+
<form action="/user_login" method="post">
41+
{% csrf_token %}
42+
<p>Email:
43+
<input type="text" name="email" placeholder="Email Address">
44+
</p>
45+
<p>Password:
46+
<input type="password" name="password" placeholder="Password">
47+
</p>
48+
<input type="submit" value="Login">
49+
</form>
50+
<div>
51+
{%if messages %}
52+
<br> {% for message in messages %}
53+
<li>{{message}}</li>
54+
{% endfor %} {% endif %}
55+
56+
</div>
57+
</body>
58+
59+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.conf.urls import url
2+
from . import views
3+
4+
5+
urlpatterns = [
6+
url(r'^$', views.index),
7+
url(r'^user_register$', views.register),
8+
url(r'^user_login$', views.login),
9+
url(r'^user_quote$', views.quotes)
10+
]
492 Bytes
Binary file not shown.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from django.shortcuts import render, redirect
2+
from .models import User
3+
from django.contrib import messages
4+
5+
6+
def index(request):
7+
return render(request, 'loginreg/index.html')
8+
9+
def register(request):
10+
# name, alias, email, password, password_confirm, dob
11+
user = User.objects.validateUser(request.POST['name'], request.POST['alias'], request.POST['email'], request.POST['password'], request.POST['confirm_password'], request.POST['birthday'])
12+
if user[0] == True:
13+
# user[1].name
14+
15+
request.session['user_id']= user[1].id
16+
request.session['user_name'] = user[1].name
17+
18+
19+
return render(request, 'loginreg/home.html')
20+
21+
for errormessage in user[1]:
22+
messages.error(request, errormessage)
23+
print errormessage
24+
return redirect('/')
25+
26+
def login(request):
27+
user = User.objects.validateLogin(request.POST['email'], request.POST['password'])
28+
print "*****"
29+
# print user[1].email
30+
#(False, [u'Email is not found in database']) if the user is not in the datebase it prints this.
31+
# (True, <User: User object>) if the user is in the datebase and its a valid login
32+
print "*****"
33+
if user[0]== True:
34+
request.session['user_id'] = user[1].id
35+
request.session['user_name'] = user[1].name
36+
return render(request, 'loginreg/home.html')
37+
else:
38+
for errormessage in user[1]:
39+
messages.error(request, errormessage)
40+
print errormessage
41+
return redirect('/')
42+
43+
44+
def quote(request):
45+
pass
Binary file not shown.

Final_Login_Registration/db.sqlite3

39 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="UTF-8"?><sqlb_project><db path="/Users/jonathankoerner/Desktop/DojoAssignments/Python/Python_stack/django/quotes/db.sqlite3" foreign_keys="1"/><window><current_tab id="1"/></window><tab_structure><column_width id="0" width="300"/><column_width id="1" width="0"/><column_width id="2" width="100"/><column_width id="3" width="2591"/><expanded_item id="0" parent="1"/><expanded_item id="1" parent="1"/><expanded_item id="2" parent="1"/><expanded_item id="3" parent="1"/></tab_structure><tab_browse><current_table name="loginreg_user"/><default_encoding codec=""/><browsetable_info data="AAAAAgAAABoAbABvAGcAaQBuAHIAZQBnAF8AdQBzAGUAcgAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAAAAAAAA//////////8AAAAA/////wAAABQAYQB1AHQAaABfAGcAcgBvAHUAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//////////AAAAAP////8="/></tab_browse><tab_sql><sql name="SQL 1"></sql><current_tab id="0"/></tab_sql></sqlb_project>

Final_Login_Registration/manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "quotes.settings")
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError:
10+
# The above import may fail for some other reason. Ensure that the
11+
# issue is really that Django is missing to avoid masking other
12+
# exceptions on Python 2.
13+
try:
14+
import django
15+
except ImportError:
16+
raise ImportError(
17+
"Couldn't import Django. Are you sure it's installed and "
18+
"available on your PYTHONPATH environment variable? Did you "
19+
"forget to activate a virtual environment?"
20+
)
21+
raise
22+
execute_from_command_line(sys.argv)

Final_Login_Registration/quotes/__init__.py

Whitespace-only changes.
186 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)