Пример #1
0
 def post(self, request):
     form = forms.LoginForm(request.POST)
     if form.is_valid():
         username = form.cleaned_data['username']
         password = form.cleaned_data['password']
         user = authenticate(username=username, password=password)
         if user is not None:
             if user.is_active:
                 login(request, user)
                 return HttpResponseRedirect(reverse('game:index'))
             else:
                 return user_util.json_response(-1, msg=u'The account is not activated, please contact administrator')
         else:
             return user_util.json_response(-1, msg=u'Username or password is incorrect')
     else:
         return user_util.json_response(-1, msg=form.errors)
Пример #2
0
    def post(self, request):
        from game.models import UserProfile

        form = forms.RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            email = form.cleaned_data['email']

            if user_util.check_exist(username, email):
                return HttpResponse('username or email already exists')
            else:
                user_util.save_user(username, password, email)
                # Direct to index page on success
                user = authenticate(username=username, password=password)

                profile = UserProfile(user=user)
                profile.save()

                login(request, user)
                return HttpResponseRedirect(reverse('game:index'))
        else:
            return user_util.json_response(-1, msg=form.errors)