コード例 #1
0
ファイル: helper.py プロジェクト: vlad508/authProjBack
def register_user(request):
    profile = Profile()
    profile.email = request.data['email']
    profile.username = request.data['email']
    if request.data.get('password') is not None:
        profile.password = make_password(request.data['password'])
    profile.first_name = request.data.get('first_name', '')
    profile.last_name = request.data.get('last_name', '')
    profile.last_login = timezone.now()

    if profile.first_name == '' and profile.last_name == '':
        profile.first_name = request.data['firstName']
        profile.last_name = request.data['lastName']
        profile.password = make_password(random_password())

    profile.save()
    return profile
コード例 #2
0
def register(request):
    """This function saves a new User to the database"""
    # A POST request will save a new user to the database
    if request.method == 'POST':
        form = UserCreateForm(data=request.POST)
        if form.is_valid():
            new_user = form.save()

            # Creates empty user profile in database
            profile = Profile(user=new_user)
            profile.email = new_user.email
            profile.save()

            # Creates empty cart in database
            cart = Cart(user=new_user)
            cart.save()

            return redirect('login')
    # If the request is not a POST a page is rendered to create a new User
    else:
        form = UserCreateForm()

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