示例#1
0
文件: views.py 项目: Czlyc/ylinux
def login (request):

    if request.method == "POST":
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            from account import authenticate,login
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    if request.session.test_cookie_worked():
                        request.session.delete_test_cookie()
                        return HttpResponseRedirect(request.session.get('login_redirect_url','/') or '/')
                else:
                    return HttpResponseForbidden(u'用户未被激活,请联系管理员: [email protected]')

    else:
        # 形如 "http://127.0.0.1:8000/account/login?next=/admin/" 的 url 可以得到 next 值
        request.session['login_redirect_url'] = request.GET.get('next')
        form = AuthenticationForm(request)

    # 登录失败,或者第一次登录,都会到这里。form可以定制很多值
    request.session.set_test_cookie()
    return {'title':'登录', 'form':form}
示例#2
0
def login(request):

    if request.method == "POST":
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            from account import authenticate, login
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    if request.session.test_cookie_worked():
                        request.session.delete_test_cookie()
                        return HttpResponseRedirect(
                            request.session.get('login_redirect_url', '/')
                            or '/')
                else:
                    return HttpResponseForbidden(
                        u'用户未被激活,请联系管理员: [email protected]')

    else:
        # 形如 "http://127.0.0.1:8000/account/login?next=/admin/" 的 url 可以得到 next 值
        request.session['login_redirect_url'] = request.GET.get('next')
        form = AuthenticationForm(request)

    # 登录失败,或者第一次登录,都会到这里。form可以定制很多值
    request.session.set_test_cookie()
    return {'title': '登录', 'form': form}
示例#3
0
def has_auth(user, passwd):

    user = authenticate(username=user, password=passwd)
    if user is not None:
        return True
    else:
        return False
示例#4
0
def login(request):

    if request.method == "POST":
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            from account import authenticate, login
            user = authenticate(username=username, password=password)
            if user is not None and user.is_active and user.is_staff:
                login(request, user)
                if request.session.test_cookie_worked():
                    request.session.delete_test_cookie()
                return HttpResponseRedirect(
                    request.session.get('previous_url', '/'))

    else:
        request.session['previous_url'] = request.META.get('HTTP_REFERER', '/')
        form = AuthenticationForm(request)

    # 登录失败,或者第一次登录,都会到这里。form可以定制很多值
    request.session.set_test_cookie()
    return {
        'title': '登录',
        'form': form,
    }
示例#5
0
def regist(request,template_name='user.regist.tpl'):
    next_url = request.GET.get("next")
    if request.method == 'POST':
        form = RegistForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            if _email_not_exists(email):
                pwd = form.cleaned_data['password']
                repwd = form.cleaned_data['repassword']
                if pwd != repwd:
                    form.errors['msg'] = u"两次密码不一致!"
                else:
                    ip = get_client_ip(request)
                    user = User.objects.create()
                    user.email = email
                    password = make_password(pwd)
                    user.password = password
                    user.regist_ip = ip
                    user.last_login_ip = ip
                    try:
                        user.save()
                        fortune = Fortune(user=user,total=10,active_point=10,left=10)
                        fortune.save()
                    except Exception,e:
                        form.errors['msg'] = u"注册失败,请重试"
                    else:
                        if request.user.is_authenticated():
                            logout(request)
                        user = authenticate(email=email,password=pwd)
                        auth_login(request,user)
                        if next_url:
                            return redirect(next_url)
                        return redirect("/")
            else:
                form.errors['msg'] = u"email已经被注册啦!"
示例#6
0
def has_auth(user, passwd):

    user = authenticate(username=user, password=passwd)
    if user is not None:
        return True
    else:
        return False
示例#7
0
def MainMenu():
    logged_in = account.authenticate()
    is_prime = account.is_prime()

    oc = ObjectContainer()

    if logged_in:
        if is_prime:
            oc.add(
                DirectoryObject(key=Callback(BrowseMenu, video_type="movies"),
                                title="Browse Movies"))
            oc.add(
                DirectoryObject(key=Callback(BrowseMenu, video_type="tv"),
                                title="Browse TV"))

        oc.add(DirectoryObject(key=Callback(LibraryMenu),
                               title="Your Library"))

        if is_prime:
            oc.add(
                DirectoryObject(key=Callback(WatchlistMenu),
                                title="Your Watchlist"))
            oc.add(
                DirectoryObject(key=Callback(SearchMenu),
                                title="Search",
                                thumb=R(PLUGIN_ICON_SEARCH)))

    oc.add(PrefsObject(title="Preferences"))

    return oc
示例#8
0
文件: forms.py 项目: Czlyc/ylinux
    def clean(self):
        username = self.cleaned_data.get('username')
        password = self.cleaned_data.get('password')

        if username and password:
            self.user_cache = authenticate(username=username, password=password)
            if self.user_cache is None:
                raise forms.ValidationError("用户名或者密码不正确,注意区分大小写!")
            elif not self.user_cache.is_active:
                #raise forms.ValidationError(_("This account is inactive."))
                raise forms.ValidationError('此账户未激活!')

        # TODO: determine whether this should move to its own method.
        if self.request:
            if not self.request.session.test_cookie_worked():
                raise forms.ValidationError(_("Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in."))

        return self.cleaned_data
示例#9
0
文件: views.py 项目: Czlyc/ylinux
def ajax_login (request):

    if request.method != "POST":
        return HttpResponse("ajax_login: Just for POST!")

    username = request.POST.get("username", None)
    password = request.POST.get("password", None)
    from account import authenticate,login
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            return {}
        else:
            return HttpResponseForbidden(u'用户未被激活,请联系管理员: [email protected]')
    else:
        return { "error": "用户名或密码错误" }
示例#10
0
def ajax_login(request):

    if request.method != "POST":
        return HttpResponse("ajax_login: Just for POST!")

    username = request.POST.get("username", None)
    password = request.POST.get("password", None)
    from account import authenticate, login
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            return {}
        else:
            return HttpResponseForbidden(
                u'用户未被激活,请联系管理员: [email protected]')
    else:
        return {"error": "用户名或密码错误"}
def MainMenu():
    logged_in = account.authenticate()
    is_prime = account.is_prime()

    oc = ObjectContainer()

    if logged_in:
        if is_prime:
            oc.add(DirectoryObject(key=Callback(BrowseMenu, video_type="movies"), title="Browse Movies"))
            oc.add(DirectoryObject(key=Callback(BrowseMenu, video_type="tv"), title="Browse TV"))

        oc.add(DirectoryObject(key=Callback(LibraryMenu), title="Your Library"))

        if is_prime:
            oc.add(DirectoryObject(key=Callback(WatchlistMenu), title="Your Watchlist"))
            oc.add(DirectoryObject(key=Callback(SearchMenu), title="Search", thumb=R(PLUGIN_ICON_SEARCH)))

    oc.add(PrefsObject(title="Preferences"))

    return oc
示例#12
0
def login(request,template_name='user.login.tpl'):
    next_url = request.GET.get("next")
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            pwd = form.cleaned_data['password']
            user = authenticate(email=email,password=pwd)
            if user is not None:
                auth_login(request,user)
                if next_url:
                    return redirect(next_url)
                return redirect("/")
            else:
                form.errors['msg'] = u"登录失败,请检查用户名和密码是否正确"
        else:
            form.errors['msg'] = u"输入信息格式不合法,请重试"
    else:
        form = LoginForm()
    return render_response(template_name,form=form,request=request,next_url=next_url)
示例#13
0
    def clean(self):
        username = self.cleaned_data.get('username')
        password = self.cleaned_data.get('password')

        if username and password:
            self.user_cache = authenticate(username=username,
                                           password=password)
            if self.user_cache is None:
                raise forms.ValidationError("用户名或者密码不正确,注意区分大小写!")
            elif not self.user_cache.is_active:
                #raise forms.ValidationError(_("This account is inactive."))
                raise forms.ValidationError('此账户未激活!')

        # TODO: determine whether this should move to its own method.
        if self.request:
            if not self.request.session.test_cookie_worked():
                raise forms.ValidationError(
                    _("Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in."
                      ))

        return self.cleaned_data
示例#14
0
def MainMenu():
    oc = ObjectContainer(no_cache=True)

    logged_in = account.logged_in()
    if not logged_in:
        logged_in = account.authenticate()

    if logged_in:
        is_prime = account.is_prime()

        if is_prime:
            oc.add(DirectoryObject(key=Callback(BrowseMenu, browse_type="movie"), title="Browse Movies"))
            oc.add(DirectoryObject(key=Callback(BrowseMenu, browse_type="tv"), title="Browse TV Shows"))

        oc.add(DirectoryObject(key=Callback(BrowseMenu, is_library=True), title="Your Library"))

        if is_prime:
            oc.add(DirectoryObject(key=Callback(BrowseMenu, is_watchlist=True), title="Your Watchlist"))
            oc.add(SearchDirectoryObject(title="Search", prompt="Search for a Movie or TV Show"))

    oc.add(PrefsObject(title="Preferences"))

    return oc
示例#15
0
文件: views.py 项目: Czlyc/ylinux
def login(request):

    if request.method == "POST":
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            from account import authenticate, login

            user = authenticate(username=username, password=password)
            if user is not None and user.is_active and user.is_staff:
                login(request, user)
                if request.session.test_cookie_worked():
                    request.session.delete_test_cookie()
                return HttpResponseRedirect(request.session.get("previous_url", "/"))

    else:
        request.session["previous_url"] = request.META.get("HTTP_REFERER", "/")
        form = AuthenticationForm(request)

    # 登录失败,或者第一次登录,都会到这里。form可以定制很多值
    request.session.set_test_cookie()
    return {"title": "登录", "form": form}
示例#16
0
def Start():
    common.set_user_agent()
    account.authenticate()

    ObjectContainer.title1 = c.PLUGIN_TITLE