Ejemplo n.º 1
0
def login(request,email = None,next_url = ''):
	if request.method == 'POST':
		form = LoginForm(request.POST)
		if form.is_valid():
			email = form.cleaned_data['email'] 
			logger.error(email)
			password = form.cleaned_data['password']
			users = User.objects.filter(email = email,profile__isnull = False)
			if users.count():
				user = users[0]
				if not user.profile.is_active:
					request.flash.now["error"] = _(u"Your account is not active.")
				else:
					user = authenticate(username=user.username,password=password)
					if user is not None:
						dlogin(request,user)
						request.flash["notice"] = _(u"You are logged in now!")
						if next_url != '':
							if next_url[0] != "/":
							    raise Http404
							else:
							    return redirect(next_url)
						else:
							return redirect(reverse(settings.DEFAULT_URL_AFTER_LOGIN))
					else:
						request.flash.now["error"] = _(u"Wrong password, please try again.")

			else:
				request.flash["error"] = _(u"Unknown e-mail address.")
		else:
			request.flash.now["error"] = _(u"Please indicate your e-mail and password.")
	else:
		form = LoginForm(initial = {'email':email})
	context = RequestContext(request)
	return render_to_response('profiles/login.html',{'form':form,'next_url':next_url},context)
Ejemplo n.º 2
0
    def post(self, request):
        """
        Logea al usuario
        :param request: Objeto httpRquest
        :return: Objeto HttpResponse con el render del formulario
         """


        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')

            # Comprobamos credenciales
            user = authenticate(username=username, password=password)

            if user is None:
                messages.error(request, 'Usuario o contraseña incorrectos')
            else:
                # login de usuario
                dlogin(request, user)
                url = request.GET.get('next', 'home')
                return redirect(url)

        form = LoginForm()

        context = {'form': form}
        messages.info(request, 'Introduzca su usuario y contraseña para acceder a su cuenta')
        return render(request, 'users/login.html', context)
Ejemplo n.º 3
0
def login(request):
    form = LoginForm(request.POST or None)
    aaaaa = form.is_valid()
    if request.method == 'POST' and form.is_valid():
        user = form.authenticate_user()
        dlogin(request, user)
        sign = request.session

        return render(request, 'signin.html')
Ejemplo n.º 4
0
def login(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(request, username=username, password=password)
        if user:
            messages.success(request, "You are now logged in!")
            dlogin(request, user)
        else:
            return render(request, 'registration/login.html')
Ejemplo n.º 5
0
def login(request):
    login_form = LogInForm()
    if request.method == "POST":
        login_form = LogInForm(request.POST)
        if login_form.is_valid():
            cd = login_form.cleaned_data
            user = authenticate(username=cd["username"], password=cd["password"])
            if user != None and user.is_authenticated():
                dlogin(request, user)
                return redirect('/')
    return render("login.html", request, {"login_form": login_form })
Ejemplo n.º 6
0
def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        dlogin(request, user)
        return render_to_response('security/success.html', {'user': user})
    if request.user is not None and request.user.is_active == True:
        return render_to_response('security/success.html',
                                  {'user': request.user})
    return render_to_response('security/login.html')
Ejemplo n.º 7
0
def join(request):
    if request.method == "POST":
        form = UserForm(request.POST)
        if form.is_valid():
            new_user = User.objects.create_user(**form.cleaned_data)
            dlogin(request, new_user)
            return redirect("/member")
        else:
            return render(request, "member/index.html",{"msg":"회원가입 실패...다시 시도해 보세요."})
    else:
        form = UserForm()
        return render(request, "member/join.html", {"form":form})
Ejemplo n.º 8
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)

        if form.is_valid():
            user = authenticate(username=form.cleaned_data['username'],
                                password=form.cleaned_data['password'])
            dlogin(request, user)
            return redirect('index')
    else:
        form = LoginForm()
    return render(request, 'account_app/login.html', {'form': form})
Ejemplo n.º 9
0
def login_check(request):
    if request.method == "POST":
        name = request.POST["username"]
        pwd = request.POST["password"]
        user = authenticate(username = name, password = pwd)
        if user is not None:
            dlogin(request, user)
            request.session["userid"] = name
            return redirect("/member/")
        else:
            return redirect(request, "member/index.html", {"msg": "로그인 실패... 다시 시도해 보세요."})
    else:
        form = LoginForm()
        return render(request, "member/login.html",{"form":form})
Ejemplo n.º 10
0
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')
            user = authenticate(username=username, password=raw_password)
            messages.success(request, f'New User Created: Welcome {username}')
            dlogin(request, user)
            return redirect('login')
    else:
        form = SignUpForm()
    return render(request, 'accounts/signup.html', {'form': form})
Ejemplo n.º 11
0
def check_login(request):
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            dlogin(request, user)
            msg = 'login'
        else:
            msg = 'disabled'
    else:
        msg = 'wrong'
    t = loader.get_template('pages/index.html')
    c = RequestContext(request, {})
    return HttpResponseRedirect('/home')
Ejemplo n.º 12
0
def login(request):
    if request.method =='POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data['email'], password=form.cleaned_data['password'])
            if user:
                dlogin(request, user)
                return redirect('home')
            else:
                messages.warning(request, 'User or Password Not Valid, Please Try Again')
        for error in form.errors:
            messages.warning(request, error)
        return redirect('login')

    else:
        form = LoginForm()
    return render(request, 'login.html', {'form':form})
Ejemplo n.º 13
0
def handlelogin(request):
    if request.method == "POST":
        # Get the post parameters
        name = request.POST['llname']
        pass1 = request.POST['lpassword1']
        user = authenticate(username=name, password=pass1)

        if user is not None:
            dlogin(request, user)
            messages.success(request, "You are loggedin successfully")
            return redirect('/')
        else:
            messages.error(request, "invalid credentials")
            return redirect('/')

    else:
        return HttpResponse("404 - Not found")
Ejemplo n.º 14
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data['username'],
                                password=form.cleaned_data['password'])
            dlogin(request, user)
            if Profile.objects.filter(user=user).exists():
                deck = request.user.profile.deck
                deck.mulligans = 0
                deck.save()
                for number in range(15):
                    card = random.choice(Card.objects.all())
                    deck.cards.add(card)
                return redirect('profile')
            return redirect('create_profile')
    else:
        form = LoginForm()
    return render(request, 'accounts/login.html', {'form': form})
Ejemplo n.º 15
0
Archivo: views.py Proyecto: Haikson/swp
def login(request):
    template = 'login.html'
    if request.method == 'POST':
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            data = login_form.cleaned_data
            user = authenticate(username=data['username'], password=data['password'])
            if user is not None:
                dlogin(request, user)
                return redirect('home')
            else:
                # the authentication system was unable to verify the username and password
                print("The username and password were incorrect.")
    else:
        login_form = LoginForm()

    context = {
        'login_form': login_form,
    }
    return render(request, template, context)
Ejemplo n.º 16
0
    def post(self, request):

        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')

            user = authenticate(username=username, password=password)

            if user is None:
                messages.error(request, 'Usuario o contraseña incorrectos')
            else:
                dlogin(request, user)
                url = request.GET.get('next', 'home')
                return redirect(url)

        form = LoginForm()

        context = {'form': form}
        return render(request, 'forms/login.html', context)
Ejemplo n.º 17
0
def login(request):
    if request.POST:
        form = LoginForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            url_next = form.cleaned_data['next']

            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    dlogin(request, user)
                    return HttpResponseRedirect(url_next)
            else:
                form.add_error(None, "The username and password are not valid.")

    else:
        next_url = request.GET.get('next', '/user/')
        form = LoginForm(initial={'next': next_url})

    return render(request, 'accounts/login.html', {'form': form})
Ejemplo n.º 18
0
def _directly_login_user(request,user):
    user.backend = "django.contrib.auth.backends.ModelBackend"
    dlogin(request,user)
Ejemplo n.º 19
0
def _directly_login_user(request, user):
    user.backend = "django.contrib.auth.backends.ModelBackend"
    dlogin(request, user)
Ejemplo n.º 20
0
def login(request):
    u_name = request.COOKIES.get('u_name')

    ret_code = 0  # 定义状态
    # if u_name:
    #     print('缓存登录。。。。。。。。。。。。。。。')
    #     return redirect('sys:index')
    # 从自定义数据库user中获取登录用户‘用户状态’,‘角色信息’
    if request.method == 'POST':
        ret_code = 0  # 返回状态
        # 从页面输入的值
        login_u_name = request.POST.get('username')
        login_u_pwd = request.POST.get('password')
        # 按照用户名、密码从Django自带的数据库auth_user数据库获取用户信息
        django_user = authenticate(username=login_u_name,
                                   password=login_u_pwd)  # 获取django提供的user表信息
        if django_user is not None:
            if django_user.is_active:  # 存在该用户,并且用户名和密码正确,则进行其他信息校验
                # 从自定义数据库user中获取登录用户‘用户状态’,‘角色信息’
                db_user = user_profile.objects.filter(
                    u_name=login_u_name).only('u_status_tsc',
                                              'system_role').first()
                u_status = db_user.u_status_tsc  # 用户状态{1:'在用',2:'冻结',3,'注销'}
                u_name = db_user.u_name
                if u_status == 0:
                    ret_info = '账号已冻结,请联系管理员或者上级部门'
                else:
                    # 用户登录成功,添加最后登录时间并写入数据库、获取用户的角色、根据角色获取用户的菜单权限信息
                    now_time = datetime.datetime.now()
                    u_id = db_user.id
                    u_role_id = db_user.system_role_id
                    u_role = db_user.system_role  # 获取用户角色
                    user_profile.objects.filter(u_name=login_u_name).update(
                        lastlogin_date=now_time, u_status_tsc=1)  # 更待用户登录状态为在线

                    # 将用户名、角色名信息存储到seesion中
                    request.session['u_id'] = str(u_id)  # 将用户的id存储到session中
                    request.session['u_name'] = str(u_name)  # 将用户名存储到session中
                    request.session['u_role'] = str(u_role)  # 将角色名存储到session中
                    request.session['u_role_id'] = str(
                        u_role_id)  # 将角色id存储到session中
                    # 从数据库中按照 角色名、菜单等级查询条件,并且按照菜单编号、父亲菜单编号排序, 查询 ‘菜单编号’,‘父亲菜单编号’,‘菜单名称’,‘是否启用’,‘url’,转换成列表,存到session中
                    menu_level1 = menu.objects.filter(
                        role__name=u_role,
                        level=1).order_by('code', 'parent_code').values_list(
                            'code', 'parent_code', 'name', 'is_Enabled_tsc',
                            'url')  # 根据角色名查询一级菜单信息

                    menu_level2 = menu.objects.filter(
                        role__name=u_role,
                        level=2).order_by('code', 'parent_code').values_list(
                            'code', 'parent_code', 'name', 'is_Enabled_tsc',
                            'url')  # 根据角色名查询二级菜单信息
                    menu_level3 = menu.objects.filter(
                        role__name=u_role,
                        level=3).order_by('code', 'parent_code').values_list(
                            'code', 'parent_code', 'name', 'is_Enabled_tsc',
                            'url')  # 根据角色名查询三级菜单信息
                    # 转成真正的列表,按照0,1,2,3,4索引取‘菜单编号’,‘父亲菜单编号’,‘菜单名称’,‘是否启用’,‘url’对应的值
                    print(menu_level1)

                    ml1 = list(menu_level1)
                    ml2 = list(menu_level2)
                    ml3 = list(menu_level3)

                    request.session['ml1'] = ml1
                    request.session['ml2'] = ml2
                    request.session['ml3'] = ml3
                    # 将用户名写到cookie中
                    response = redirect('sm:index')
                    response.set_cookie('u_name', u_name)
                    dlogin(request, django_user)  # 登录成功,用django自带的用户认证,并且跳转首页
                    # return response  # 登录成功,跳转首页
                    ret_info = '登录成功'
                    ret_code = 1

        else:
            ret_info = '账号或密码错误'

        return HttpResponse(
            json.dumps({
                'ret_info': ret_info,
                'ret_code': ret_code
            }))
    else:  # 否则为get方法
        next_to = request.GET.get('next', False)
        if request.user:  # 判断用户是否登录成功
            if next_to:
                return redirect(next_to)

    return render(request, 'login.html')  # 为登录成功,跳转到登录界面