Beispiel #1
0
 def authenticate(self, request, username=None, password=None):
     username = self.sanitizate(username)
     user = django_auth(request, username=username, password=password)
     if user is None:
         try:
             userObject = Usuario.objects.get(email=username)
         except Usuario.DoesNotExist:
             print('usuario no existe')
             return None
         user = django_auth(request,
                            username=userObject.username,
                            password=password)
     return user
Beispiel #2
0
def login(request):
    """ Try to log in a user """
    if request.method == 'POST':
        username = request.POST.get('username', '')
        password = request.POST.get('password', '')
        site = request.POST.get('next', '/manage')

        user = django_auth(username=username, password=password)

        if user is not None:
            if user.is_active:
                django_login(request, user)
                return redirect(site)

    form = AuthenticationForm(request)

    form.fields['username'].widget.attrs.update({
            'placeholder': 'username'
        })
    form.fields['password'].widget.attrs.update({
            'placeholder': 'password'
        })

    site = request.GET.get('next', '/manage')

    return render(request, 'blog/login.html', {
        'form': form,
        'next': site,
        'request': request,
    })
Beispiel #3
0
def login(request):
    if request.method == 'POST':
        if request.body is None or request.body == '':
            return JsonResponse({
                'code': ERROR_LOGIN_WRONG_PARAMS,
            })
        json_data = json.loads(request.body)
        username = request.POST.get('username', json_data.get('username'))
        password = request.POST.get('password', json_data.get('password'))
        print username, password
        res = None
        if username is None or password is None:
            res = JsonResponse({
                'code': ERROR_LOGIN_WRONG_PARAMS,
            })
            return res
        # 验证用户名/密码合法性
        user = django_auth(username=username, password=password)
        if user is None:
            # 用户名/密码非法
            res = JsonResponse({'code': ERROR_LOGIN_WRONG_USERNAME_PASSWORD})
            return res
        else:
            django_login(request, user)
            res = JsonResponse({'code': ERROR_LOGIN_OK})
            return res
    else:
        res = JsonResponse({'code': ERROR_LOGIN_ONLY_POST})
        return res
Beispiel #4
0
def login(request):
    if request.method == 'POST':
        if request.body is None or request.body == '':
            return JsonResponse({
                'code': ERROR_LOGIN_WRONG_PARAMS,
            })
        json_data = json.loads(request.body)
        username = request.POST.get('username', json_data.get('username'))
        password = request.POST.get('password', json_data.get('password'))
        print username, password
        res = None
        if username is None or password is None:
            res = JsonResponse({
                'code': ERROR_LOGIN_WRONG_PARAMS,
                })
            return res
        # 验证用户名/密码合法性
        user = django_auth(username=username, password=password)
        if user is None:
            # 用户名/密码非法
            res = JsonResponse({
                'code': ERROR_LOGIN_WRONG_USERNAME_PASSWORD
                })
            return res
        else:
            django_login(request, user)
            res = JsonResponse({
                'code': ERROR_LOGIN_OK
                })
            return res
    else:
        res = JsonResponse({
            'code': ERROR_LOGIN_ONLY_POST})
        return res
Beispiel #5
0
 def login(self, request):
     user = django_auth(username=self.cleaned_data['email'], password=self.cleaned_data['password'])
     if user is not None:
         if user.is_active:
             django_login(request, user)
             return True
         else:
             return False
     return False
Beispiel #6
0
    def save(self, request):
        user = User.objects.create_user(
            username=self.cleaned_data['email'], 
            email=self.cleaned_data['email'],
            password=self.cleaned_data['password'])
        user.save()

        # Log user in
        user = django_auth(username=self.cleaned_data['email'], password=self.cleaned_data['password'])
        django_login(request, user)
Beispiel #7
0
 def authenticate(self, username, password):
     """
     Authenticates user.
     :param username: User's name.
     :param password: Password.
     :return: User instance.
     """
     user = django_auth(username=username, password=password)
     if user and not user.is_active:
         user = None
     return user
Beispiel #8
0
 def post(self, request, format=None):
     username = request.POST['username']
     print "signin username:"******"signin password:"******"SIGN IN ERROR"
Beispiel #9
0
def do_basic_auth(request):
	try:
		auth_string = request.META['HTTP_AUTHORIZATION']
		shit, moreshit, thestring = auth_string.partition(' ')
		username, sep, password =  thestring.decode('base64').partition(':')
		user = django_auth(username = username, password = password)
		if user is None:
			resp = HttpResponse()
			resp.status_code = 403
		else:
			resp = HttpResponse()
			resp.status_code = 200
	except KeyError, e:
		resp = HttpResponse()
		resp.status_code = 401
		resp['WWW-Authenticate'] = 'Basic Realm = "18SG JACAS"'
Beispiel #10
0
def login(request, redirect_field_name=REDIRECT_FIELD_NAME):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('dashboard_home'))

    if request.POST:
        login_form = PPUserLoginForm(data=request.POST)

        if login_form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = django_auth(username=username, password=password)

            if user is not None:
                if user.is_active:
                    redirect_to = request.POST.get(
                        redirect_field_name,
                        request.GET.get(redirect_field_name, ''))

                    # Ensure the user-originating redirection url is safe.
                    if not is_safe_url(url=redirect_to,
                                       host=request.get_host()):
                        redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)

                    django_login(request, user)

                    return HttpResponseRedirect(redirect_to)

                else:
                    # Return a 'disabled account' error message
                    print('asdf')
                    pass
            else:
                # Return an 'invalid login' error message.
                print('asdf')
    else:
        login_form = PPUserLoginForm()

    return render(request, 'accounts/login.html', {'form': login_form})
Beispiel #11
0
def login(request):
    if request.method == 'POST':
        json_data = json.loads(request.body)
        username = request.POST.get('username', json_data.get('username'))
        password = request.POST.get('password', json_data.get('password'))
        # headers = request.POST.get('headers', json_data.get('headers'))
        # print("headers:  "+headers)
        print("username: "******"password" + password)
        user = django_auth(username=username, password=password)
        if user is None:
            # 用户名/密码非法
            res = JsonResponse({'code': ERROR_LOGIN_WRONG_USERNAME_PASSWORD})
            return res
        else:
            django_login(request, user)
            res = JsonResponse({
                'name':
                user.username,
                'code':
                ERROR_LOGIN_OK,
                'user_email':
                user.email,
                'user_s':
                user.is_superuser,
                'success':
                True,
                'token':
                default_token_generator.make_token(user),
                'user':
                user.pk,
            })
            return res
            # token = Token.objects.get(user=user)
            # serializer = TokenSerializer(token)
            # return Response(serializer.data, status=status.HTTP_202_ACCEPTED)

    return None
def login(request, redirect_field_name=REDIRECT_FIELD_NAME):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('dashboard_home'))

    if request.POST:
        login_form = PPUserLoginForm(data=request.POST)

        if login_form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = django_auth(username=username, password=password)

            if user is not None:
                if user.is_active:
                    redirect_to = request.POST.get(redirect_field_name,
                                   request.GET.get(redirect_field_name, ''))

                    # Ensure the user-originating redirection url is safe.
                    if not is_safe_url(url=redirect_to, host=request.get_host()):
                        redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)

                    django_login(request, user)

                    return HttpResponseRedirect(redirect_to)

                else:
                    # Return a 'disabled account' error message
                    print('asdf')
                    pass
            else:
                # Return an 'invalid login' error message.
                print('asdf')
    else:
        login_form = PPUserLoginForm()

    return render(request, 'accounts/login.html', {'form': login_form})
Beispiel #13
0
    cur_level = [i.name for i in SongLevel.objects.all()]
    for l in level:
        if l not in cur_level:
            new_level = SongLevel(name=l)
            new_level.save()

    # Insert style
    styles = set(nrows[:,3])
    cur_styles = [i.name for i in SongStyle.objects.all()]
    for s in styles:
        if s not in cur_styles:
            new_style = SongStyle(name=s)
            new_style.save()

    # Get test user
    user = django_auth(username='******', password='******')

    # Insert songs
    cur_songs = [i.title for i in Song.objects.all()]
    for s in rows:
        title = s[0]
        artist   = s[1]
        composer = s[2]
        style = s[3]
        level = s[4]
        chord = s[5]
        yt_url = s[6]
        note_url = s[7]

        yt_id = yt_url.split('v=')[-1]
 def validate(self, data):
     username = data.get('username', '')
     password = data.get('password', '')
     user = django_auth(username=username, password=password)
     data['user'] = user
     return data
Beispiel #15
0
 def authenticate(username=None, password=None):
     user = django_auth(username=username, password=password)
     if user and user.is_verified:
         return user
     else:
         return None