i m using only email for sign up and sending the random password  on the
mail which will be used for login
Now I want login to be done using register email and password send to mail
I m stuck here that I m generating random password but how I will save as
password and email in my 'views.Py ' file .so that email password can be
used for login
 Please need help

views.py:
from django.shortcuts import render
from profilestorer.settings import EMAIL_HOST_USER
from .forms import SignUp
from django.core.mail import send_mail
from django.utils.crypto import get_random_string
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect, HttpResponse

# Create your views here.
@login_required
def user_logout(request):
    logout(request)
    return HttpResponseRedirect(reverse('company-login'))


def register(request):
        form =SignUpForm()
        if request.method == 'POST':
            form = SignUpForm(data=request.POST)
            unique_id = get_random_string(length=8)
            subject = 'Welcome to profile storer'
            message = 'Please enter this password for login :   ' +
unique_id
            recepient = str(form['Email'].value())
            send_mail(subject,
                message, EMAIL_HOST_USER, [recepient], fail_silently =
False)
            return render(request, 'company/success.html', {'recepient':
recepient})


        return render(request, 'company/register.html', {'form':form})

forms.py:

from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import User


class SignUp(UserCreationForm):
    email = forms.EmailField(max_length=200)

    class Meta:
        model = User
        fields =('email')

models.py:

from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class User(models.Model):
    email = models.EmailField()
    password = models.CharField(max_length=50)

    def __str__(self):                                #will return search
add by the user
        return '{}'.format(self.email)

    class Meta:
        verbose_name_plural = 'User'

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMtmBS9Dttmx17L5rhE9qqXS-sOYkdqkvuOUfq5piKoHsVKVqA%40mail.gmail.com.

Reply via email to