Commit e5014a01 authored by Brian Guadalupe's avatar Brian Guadalupe

Create app `user`

parent 2625c788
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class UserConfig(AppConfig):
name = 'user'
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class SignUpForm(UserCreationForm):
first_name = forms.CharField(max_length=255)
last_name = forms.CharField(max_length=255)
email = forms.EmailField(max_length=255, help_text='Please enter a valid email address.')
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2', )
from django.db import models
class UserAccount(models.Model):
id = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=64)
last_name = models.CharField(max_length=64)
email = models.CharField(max_length=64)
from django.test import TestCase
# Create your tests here.
from django.contrib.auth import login, authenticate
from django.contrib.auth.models import User
from django.shortcuts import render, redirect, get_object_or_404
from django.views.generic.edit import UpdateView
from user.forms import SignUpForm
from user.models import *
def signup(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')
return redirect('/')
else:
form = SignUpForm()
return render(request, 'signup.html', {'form': form})
def user_profile_page(request, slug):
user = get_object_or_404(User, username=slug)
return render(request, 'profile.html', {'profile': user})
class EditProfile(UpdateView):
model = User
fields = ['username', 'email', 'first_name', 'last_name']
template_name = 'edit_profile.html'
slug_field = 'username'
slug_url_kwarg = 'slug'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment