Example #1
0
def signin(request):
    try:
        if request.method == "POST" and "form-username" in request.POST:
            if request.POST['form-username'] and request.POST['form-password']:
                user = authenticate(username=request.POST['form-username'],
                                    password=request.POST['form-password'])
                if user and user.is_active:
                    # account exists and is enabled
                    request.session['username'] = user.username
                    request.session['userid'] = user.id
                    return render(
                        request, "what/redirect.html", {
                            "redirect_url": Utils.get_app_url(),
                            "message": "login_success",
                        })
                elif user:
                    # account exists but is disabled
                    return render(request, "what/login.html",
                                  {"message": "account_disabled"})
                else:
                    # username or password incorrect
                    return render(request, "what/login.html",
                                  {"message": "login_error"})
            else:
                # username and/or password missing
                return render(request, "what/login.html", {
                    "message": "login_missing",
                })
        else:
            # show the login form
            return render(request, "what/login.html", {
                "message": "form_login",
            })
    except KeyError:
        return render(request, "what/login.html", {"message": "login_missing"})
Example #2
0
def signin(request):
	try:
		if request.method == "POST" and "form-username" in request.POST:
			if request.POST['form-username'] and request.POST['form-password']:
				user = authenticate(username=request.POST['form-username'],
					password=request.POST['form-password'])
				if user and user.is_active:
					# account exists and is enabled
					request.session['username'] = user.username
					request.session['userid'] = user.id
					return render(request, "what/redirect.html", {
						"redirect_url": Utils.get_app_url(),
						"message": "login_success",
						})
				elif user:
					# account exists but is disabled
					return render(request, "what/login.html",
						{"message": "account_disabled"})
				else:
					# username or password incorrect
					return render(request, "what/login.html",
						{"message": "login_error"})
			else:
				# username and/or password missing
				return render(request, "what/login.html", {
					"message": "login_missing",
					})
		else:
			# show the login form
			return render(request, "what/login.html", {
				"message": "form_login",
				})
	except KeyError:
		return render(request, "what/login.html", {"message": "login_missing"})
Example #3
0
def signout(request):
    logout(request)
    if "username" in request.session:
        del request.session['username']
    if "userid" in request.session:
        del request.session['userid']
    return render(request, "what/redirect.html", {
        "redirect_url": Utils.get_app_url(),
        "message": "logout_success",
    })
Example #4
0
def signout(request):
	logout(request)
	if "username" in request.session:
		del request.session['username']
	if "userid" in request.session:
		del request.session['userid']
	return render(request, "what/redirect.html", {
		"redirect_url": Utils.get_app_url(),
		"message": "logout_success",
		})