Skip to content

Commit

Permalink
added signup pages
Browse files Browse the repository at this point in the history
  • Loading branch information
suhailvs committed Apr 28, 2021
1 parent 24985ab commit 3579647
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 499 deletions.
17 changes: 0 additions & 17 deletions Pipfile

This file was deleted.

455 changes: 0 additions & 455 deletions Pipfile.lock

This file was deleted.

29 changes: 8 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,7 @@ Please take a look at the link below for more information:
https://channels.readthedocs.io/en/latest/introduction.html


**update 04/06/19**

- using pipenv for package management
- move to Channels 2
- use redis as the channel layer backing store. for more information, please check [channels_redis](https://github.com/django/channels_redis)

### Database ###
For this demo, I'm using a simple MySQL setup. If more performance is required,
a MySQL cluster / shard could be deployed.

PD: I'm using indexes to improve performance.

## Assumptions ##
Because of time constraints this project lacks of:
Expand All @@ -65,36 +55,33 @@ Because of time constraints this project lacks of:

1. Create and activate a virtualenv (Python 3)
```bash
pipenv --python 3 shell
python3 -m venv env
```
2. Install requirements
```bash
pipenv install
pip install -r requirements.txt
```
3. Create a MySQL database
```sql
CREATE DATABASE chat CHARACTER SET utf8;
```
4. Start Redis Server

3. Start Redis Server
```bash
redis-server
```

5. Init database
4. Init database
```bash
./manage.py migrate
```
6. Run tests
5. Run tests
```bash
./manage.py test
```

7. Create admin user
6. Create admin user
```bash
./manage.py createsuperuser
```

8. Run development server
7. Run development server
```bash
./manage.py runserver
```
Expand Down
3 changes: 2 additions & 1 deletion chat/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'core',

# 3rd party
'crispy_forms',
'rest_framework',
'channels',
]
Expand Down Expand Up @@ -143,7 +144,7 @@

USE_TZ = True
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

CRISPY_TEMPLATE_PACK = 'bootstrap4'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/

Expand Down
8 changes: 3 additions & 5 deletions chat/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from core.signup import SignUpView

urlpatterns = [

path('admin/', admin.site.urls),

path('', include('core.urls')),

path('signup/', SignUpView.as_view(), name='signup'),
path('login/', auth_views.LoginView.as_view(), name='login'),

path('logout/', auth_views.LogoutView.as_view(), {'next_page': '/'},
name='logout')

path('logout/', auth_views.LogoutView.as_view(next_page='/'), name='logout'),
]
36 changes: 36 additions & 0 deletions core/signup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django import forms
from django.core.exceptions import ValidationError
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from django.views.generic import CreateView
from django.urls import reverse

class SignUpForm(UserCreationForm):
email = forms.EmailField(required=True)

def uniqueemailvalidator(self, value):
if User.objects.filter(email__iexact=value).exists():
raise ValidationError('User with this Email already exists.')

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['email'].validators.append(self.uniqueemailvalidator)

class Meta(UserCreationForm.Meta):
model = User
fields = ['username', 'email', 'password1','password2']

def save(self, commit=True):
user = super().save(commit=False)
user.email = self.cleaned_data["email"]
if commit:
user.save()
return user

class SignUpView(CreateView):
model = User
form_class = SignUpForm
template_name = 'registration/signup.html'

def get_success_url(self):
return reverse('home')
85 changes: 85 additions & 0 deletions core/templates/registration/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}Django Social Network{% endblock %}</title>
<link rel="icon" type="image/png" href="{% static 'img/favicon.png' %}">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<!-- <link href="{% static 'css/bootcamp.css' %}?v=1" rel="stylesheet"> -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style type="text/css">
body {
background-color: #14213d; /* 006389,073b4c */
margin-top: 60px;
}
.logo {
margin: 0;
font-size: 2em;
font-weight: 200;
font-family: "Audiowide", cursive;
color: #92c35e;
text-align: center;
text-shadow: 1px 1px 0 #333333;
line-height: 70px;
}

.login-or {
position: relative;
color: #aaa;
margin-top: 10px;
margin-bottom: 10px;
padding-top: 10px;
padding-bottom: 10px;
}
.span-or {
display: block;
position: absolute;
left: 50%;
top: -2px;
margin-left: -25px;
background-color: #fff;
width: 50px;
text-align: center;
}
.hr-or {
height: 1px;
margin-top: 0px !important;
margin-bottom: 0px !important;
}
</style>

</head>
<body>
<a href="https://github.com/suhailvs/django-whatsapp"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>

<div class="container">
<div class="row">
<div class="{% block col_class %}col-md-4 col-sm-8 col-12 offset-md-4{% endblock col_class %}">
<p class="logo">Django Whatsapp</p>
<div class="card">
<h4 class="card-header">{% block cardheader %}Log in{% endblock cardheader %}</h4>
<div class="card-body">
{% if form.non_field_errors %}
<div class="alert alert-danger alert-dismissible fade show" role="alert">
{% for error in form.non_field_errors %}
<p{% if forloop.last %} class="mb-0"{% endif %}>{{ error }}</p>
{% endfor %}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
{% endif %}
{% block form %}{% endblock form %}
</div>
</div>
</div>
</div>
</div>
</body>
</html>
20 changes: 20 additions & 0 deletions core/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends 'registration/base.html' %}

{% load crispy_forms_tags %}

{% block form %}
<form method="post" novalidate>
{% csrf_token %}
<input type="hidden" name="next" value="{{ next }}">
{{ form.username|as_crispy_field }}
{{ form.password|as_crispy_field }}
<button type="submit" class="btn btn-primary btn-block">Log in</button>
<div class="login-or">
<hr class="hr-or">
<span class="span-or">or</span>
</div>
<p class="text-center">Don't have account? <a href="{% url 'signup' %}">Sign up here</a></p>

</form>
{% endblock form %}

20 changes: 20 additions & 0 deletions core/templates/registration/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends 'registration/base.html' %}

{% load crispy_forms_tags %}

{% block col_class %}col-md-6 col-sm-12 offset-md-3{% endblock col_class %}
{% block cardheader %}Sign up{% endblock cardheader %}

{% block form %}
<form method="post" novalidate>
{% csrf_token %}
<input type="hidden" name="next" value="{{ next }}">
{{ form|crispy }}
<button type="submit" class="btn btn-success btn-block">Create an account</button>
<div class="login-or">
<hr class="hr-or">
<span class="span-or">or</span>
</div>
<p class="text-center"><a href="{% url 'login' %}">Already have an account?</a></p>
</form>
{% endblock form %}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ django-filter
channels
channels-redis
Django
django-crispy-forms

0 comments on commit 3579647

Please sign in to comment.