Skip to content

Commit

Permalink
'first'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ammar-hala committed Sep 4, 2020
0 parents commit a012567
Show file tree
Hide file tree
Showing 95 changed files with 1,529 additions and 0 deletions.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions simplesocial/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions simplesocial/accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
name = 'accounts'
13 changes: 13 additions & 0 deletions simplesocial/accounts/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.forms import UserCreationForm

class UserCreateForm(UserCreationForm):

class Meta():
fields = ('username' , 'email' , 'password1' , 'password2')
model = get_user_model()

def __init__(self , *args , **kwargs):
super().__init__(*args , **kwargs)
self.fields['username'].label = 'Display Name' # setting label here like did in html files... it's mandatory
self.fields['email'].label = 'Email Address'
32 changes: 32 additions & 0 deletions simplesocial/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.1 on 2020-08-25 14:19

import django.contrib.auth.models
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='auth.user')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
bases=('auth.user', models.Model),
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
Empty file.
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions simplesocial/accounts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models
from django.contrib import auth
# Create your models here.

class User(auth.models.User , auth.models.PermissionsMixin): # all work is done by django..

def __str__(self):
return '@{}'.format(self.username) # username comes with class User
17 changes: 17 additions & 0 deletions simplesocial/accounts/templates/accounts/change_password.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "base.html" %}
{% load bootstrap3 %}

{% block content %}

<div class="container">
<h1>Change Password</h1>
<form method="POST">
{% csrf_token %}
{% bootstrap_form form %}
<input type="submit" class="btn btn-default" value="Change Password">

</form>

</div>

{% endblock %}
18 changes: 18 additions & 0 deletions simplesocial/accounts/templates/accounts/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'base.html' %}
{% load bootstrap3 %}

{% block content %}

<div class="container">
<h1>Log In</h1>
<form method="POST">
{% csrf_token %}
{% bootstrap_form form %}
<input type="submit" class="btn btn-default" value="Log In">
<a href="{% url 'accounts:password_reset' %}"> Forgot Password? </a>

</form>

</div>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends 'base.html' %}

{% block content %}
<p>
Your password has been set. You may go ahead and <a href="{% url 'accounts:login' %}"> Login </a> now.
</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends 'base.html' %}
{% load bootstrap3 %}

{% block content %}

{% if validlink %}
<h3>Change password</h3>

<form method="POST">

{% csrf_token %}
{% bootstrap_form form %}
<input type="submit" class="btn btn-default" value="Submit">

</form>

{% else %}

<p>
The password reset link was invalid, possibly because it has already been used.
Please request a new password reset.
</p>

{% endif %}

{% endblock %}
12 changes: 12 additions & 0 deletions simplesocial/accounts/templates/accounts/password_reset_done.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'base.html' %}

{% block content %}
<p>
We've emailed you instructions for setting your password, if an account exists with the email you entered.
You should receive them shortly.
</p>
<p>
If you don't receive an email, please make sure you've entered the address you registered with,
and check your spam folder.
</p>
{% endblock %}
41 changes: 41 additions & 0 deletions simplesocial/accounts/templates/accounts/password_reset_email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!-- {% autoescape off %}
To initiate the password reset process for your {{ user.get_username }} TestSite Account,
click the link below:
{{ protocol }}://{{ domain }}{% url 'accounts:password_reset_confirm' uidb64=uid token=token %}
If clicking the link above doesn't work, please copy and paste the URL in a new browser
window instead.
Sincerely,
The TestSite Team
{% endautoescape %}
<!-- {% load i18n %} -->

{% load i18n %}
{% autoescape off %}

{% blocktrans %}
You're receiving this email because you requested a password reset for your user account at {{ site_name }}.
{% endblocktrans %}

{% trans "Please go to the following page and choose a new password:" %}
{% block reset_link %}

{{ protocol }}://{{ domain }}{% url 'accounts:password_reset_confirm' uidb64=uid token=token %}

{% endblock %}

{% trans "Your username, in case you've forgotten:" %}

{{ user.get_username }}

{% trans "Thanks for using our site!" %}

{% blocktrans %}

The {{ site_name }} team

{% endblocktrans %}

{% endautoescape %}
15 changes: 15 additions & 0 deletions simplesocial/accounts/templates/accounts/password_reset_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "base.html" %}
{% load bootstrap3 %}

{% block content %}

<h3> Forgot Password </h3>
<form method="POST">

{% csrf_token %}
{% bootstrap_form form %}
<input type="submit" class="btn btn-default" value="Submit">

</form>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Social Site Password Reset
17 changes: 17 additions & 0 deletions simplesocial/accounts/templates/accounts/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'base.html' %}
{% load bootstrap3 %}

{% block content %}

<div class="container">
<h1>Sign Up</h1>
<form method="POST">
{% csrf_token %}
{% bootstrap_form form %}
<input type="submit" class="btn btn-default" value="Sign Up">

</form>

</div>

{% endblock %}
3 changes: 3 additions & 0 deletions simplesocial/accounts/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
24 changes: 24 additions & 0 deletions simplesocial/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.urls import path , include
from django.contrib.auth import views as auth_views # django has builtin login view and logout view so we dont have to create it

from . import views

app_name = 'accounts'
urlpatterns = [
path('login/' , auth_views.LoginView.as_view(template_name = 'accounts/login.html') , name='login') ,
path('logout/' , auth_views.LogoutView.as_view() , name='logout') , # it will take you to home page after you logout
path('signup/' , views.SignUp.as_view() , name='signup') ,
path('password/' , views.change_pass , name='change_password') ,

# for password reset... can read about reset password here - > https://simpleisbetterthancomplex.com/tutorial/2016/09/19/how-to-create-password-reset-view.html
# path('' , include('django.contrib.auth.urls') ) ,

# OR see in that link
path('password_reset/', auth_views.PasswordResetView.as_view(template_name = 'accounts/password_reset_form.html' , subject_template_name = 'accounts/password_reset_subject.txt' , email_template_name = 'accounts/password_reset_email.html') , name='password_reset'),
path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(template_name = 'accounts/password_reset_done.html') , name='password_reset_done'),
path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(template_name = 'accounts/password_reset_confirm.html') , name='password_reset_confirm'),
path('reset/done/', auth_views.PasswordResetCompleteView.as_view(template_name = 'accounts/password_reset_complete.html') , name='password_reset_complete'),

# path('' , include('django.contrib.auth.urls') ) ,

]
38 changes: 38 additions & 0 deletions simplesocial/accounts/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.shortcuts import render , get_object_or_404 , redirect
from django.views.generic import (TemplateView , ListView , DetailView , CreateView , UpdateView , DeleteView)
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.decorators import login_required
from django.urls import reverse_lazy

#for password change
from django.contrib import messages
from django.contrib.auth import update_session_auth_hash #important for changin password
from django.contrib.auth.forms import PasswordChangeForm #built in form

from .models import User
from . import forms
# Create your views here.
class SignUp(CreateView):
template_name = 'accounts/signup.html'
form_class = forms.UserCreateForm
success_url = reverse_lazy('login') # once soeomeone has signed up.. take then to login page


def change_pass(request):
if request.method == 'POST':
form = PasswordChangeForm(request.user , request.POST) #so that form gets the authenticated user


if form.is_valid():
user = form.save()
update_session_auth_hash(request , user) # importatnt cos else after saving form.. user's auth session will be invalidated and he will have to login again
messages.success(request , 'Your Password was succesfullu updated.')
return redirect('test')

else:
messages.error(request , 'Form not Valid!')

else:
form = PasswordChangeForm(request.user)

return render(request , 'accounts/change_password.html' , {'form' : form} )
Binary file added simplesocial/db.sqlite3
Binary file not shown.
Empty file added simplesocial/groups/__init__.py
Empty file.
Binary file not shown.
Binary file added simplesocial/groups/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file added simplesocial/groups/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions simplesocial/groups/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin
from groups.models import Group , GroupMember
# Register your models here.

class GroupMemberInline(admin.TabularInline):
model = GroupMember # so can edit it inside from Group... since Group is it's parent

admin.site.register(Group)
5 changes: 5 additions & 0 deletions simplesocial/groups/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class GroupsConfig(AppConfig):
name = 'groups'
46 changes: 46 additions & 0 deletions simplesocial/groups/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 3.1 on 2020-08-29 11:21

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Group',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=256, unique=True)),
('slug', models.SlugField(allow_unicode=True, unique=True)),
('descriptions', models.TextField(blank=True, default='')),
('description_html', models.TextField(blank=True, default='', editable=False)),
],
options={
'ordering': ['name'],
},
),
migrations.CreateModel(
name='GroupMember',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='memberships', to='groups.group')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_groups', to=settings.AUTH_USER_MODEL)),
],
options={
'unique_together': {('group', 'user')},
},
),
migrations.AddField(
model_name='group',
name='members',
field=models.ManyToManyField(through='groups.GroupMember', to=settings.AUTH_USER_MODEL),
),
]
18 changes: 18 additions & 0 deletions simplesocial/groups/migrations/0002_auto_20200829_1651.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1 on 2020-08-29 11:51

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('groups', '0001_initial'),
]

operations = [
migrations.RenameField(
model_name='group',
old_name='descriptions',
new_name='description',
),
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit a012567

Please sign in to comment.