예제 #1
0
def authenticate(username, password, permission=None):
    """
    Authenticate staff_user with permission.
    """
    author = authen(username=username, password=password)
    if not author:
        raise Fault(LOGIN_ERROR, _('Username or Password is incorrect.'))
    if not author.is_staff or not author.is_active:
        raise Fault(PERMISSION_DENIED, _('User account unavailable.'))
    if permission:
        if not author.has_perm(permission):
            raise Fault(PERMISSION_DENIED, _('User cannot %s.') % permission)
    return author
예제 #2
0
def Login(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            user = authen(username=cd['username'], password=cd['password'])
            # print(user)
            if user:
                login(request,user)
                return redirect('chat')
    else:
        form = LoginForm()
        return render(request,'accounts/login.html',{'form':form,})
    return render(request,'accounts/login.html',{'form':form,'error':"User DoesNot Exists"})
예제 #3
0
def SignUp(request):
        if request.method == "POST":
            form = SignUpForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                print(cd)
                user = User.objects.create_user(cd['username'],cd['email'],cd['password'])
                user.save()
                user = authen(username=cd['username'], password=cd['password'])
                login(request,user)
                return redirect('chat')
                # return render(request,'chat/chat.html',{'user':user})
        else:
            form = SignUpForm()
        return render(request,'accounts/signup.html',{'form':form})
예제 #4
0
def login_view(request):
	if request.method == "GET":
		return render(request, 'myapp/login.html')
	if request.method == "POST":
		#form = LoginForm(request.POST) # A form bound to the POST data
		if True:	#form.is_valid(): # All validation rules pass
			username = request.POST['username']
			password = request.POST['password']
			user = authen(username=username, password=password)
			if user is not None:
				# Redirect to a success page.
				login(request, user)
				# return render(request, 'myapp/home.html')
				return redirect ('/home/')
			else:
				error = 'Invalid credentials'
				return render(request, 'myapp/login.html', { 'error': error })
		else:
			error = 'Something went wrong! Please try again.'
			return render(request, 'myapp/login.html', { 'error': error })
예제 #5
0
def signup(request):
	if request.method == "GET":
		return redirect('login')

	if request.method == "POST":
		#form = LoginForm(request.POST)
		if True: #form.is_valid():
			username = request.POST['username']
			password = request.POST['password']
			first_name = request.POST['first_name']
			last_name = request.POST['last_name']
			user = authen(username=username, password=password)
			if user is None:
				user = User.objects.create_user(username=username, email=username, password=password, first_name=first_name, last_name=last_name)
				login(request, user)
				UserGraph().insert_user(username)
				return render(request, 'myapp/home.html')
			else:
				error = 'User already exists'
				return render(request, 'myapp/login.html', { 'error': error })
		else:
			error = 'Something went wrong! Please try again.'
			return render(request, 'myapp/login.html', { 'error': error })