Пример #1
0
    def register(cls,
                 email,
                 username='',
                 password='',
                 active=True,
                 commit=True,
                 **kwargs):

        name = email[:email.find('@')]
        if not username:
            username = name + str(int(timezone.now().timestamp()))
        if not password:
            password = UserModel.objects.make_random_password()
        user = UserModel(username=email, email=email, is_active=active)
        user.set_password(password)
        profile = UserProfile(email=email,
                              username=username,
                              name=name,
                              **kwargs)
        if commit:
            with transaction.atomic():
                user.save()
                profile.user = user
                profile.save()
        return profile, password
Пример #2
0
    def test_permission_denied_to_non_admin(self):
        req = RequestFactory().get('/')
        req.user = UserModel()
        req.user.is_administrator = False

        self.assertRaises(PermissionDenied, category.category_list, req)
        self.assertRaises(PermissionDenied, category.category_create, req)
        self.assertRaises(PermissionDenied, category.category_update, req)

        self.assertRaises(PermissionDenied, comment_flag.flag_closed, req)
        self.assertRaises(PermissionDenied, comment_flag.flag_open, req)
        self.assertRaises(PermissionDenied, comment_flag.flag_detail, req)

        self.assertRaises(PermissionDenied, config.config_basic, req)

        self.assertRaises(PermissionDenied, index.dashboard, req)

        self.assertRaises(PermissionDenied, topic.topic_deleted, req)
        self.assertRaises(PermissionDenied, topic.topic_closed, req)
        self.assertRaises(PermissionDenied, topic.topic_pinned, req)

        self.assertRaises(PermissionDenied, user.user_edit, req)
        self.assertRaises(PermissionDenied, user.user_list, req)
        self.assertRaises(PermissionDenied, user.user_admins, req)
        self.assertRaises(PermissionDenied, user.user_mods, req)
        self.assertRaises(PermissionDenied, user.user_unactive, req)
Пример #3
0
    def create_one(cls, request):
        body = get_body(request)
        schema = Object({'data': Object({
            'type': String(cls.TYPE),
            'attributes': Object(
                {'username': String(),
                 'password': String(),
                 'first_name': String(),
                 'last_name': String()},
                required=['username', 'password'],
            )
        })})
        raise_for_body(body, schema)

        attributes = dict(body['data']['attributes'])
        if UserModel.objects.filter(username=attributes['username']).exists():
            raise Conflict(f"User with username '{attributes['username']}' "
                           f"already exists")

        password = attributes.pop('password')
        user = UserModel(**attributes)
        user.set_password(password)
        user.save()

        return user
Пример #4
0
def register(request):
    if request.user.is_authenticated:
        return render(request, 'logoutFst.html')
    if request.method == 'POST':
        usr = UserModel(email=request.POST['email'],
                        username=request.POST['username'],
                        password=request.POST['password'],
                        is_superuser=0,
                        is_staff=0,
                        is_active=1,
                        date_joined=datetime.datetime.today(),
                        first_name="foo",
                        last_name='foo')
        usr.save()
        login(request, usr)
        return redirect('iamdbApp:index')
    else:
        return render(request, 'register.html')
Пример #5
0
def application_detail(request, pk):
    application = Application.objects.get(pk=pk)
    form = UserCreationForm

    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            if request.user.is_authenticated():
                user = request.user
            else:
                user = UserModel(username=form.cleaned_data['username'],
                                 password1=form.cleaned_data['password1'],
                                 password2=form.cleaned_data['password2'])
                user.save()

            user_application = UserApplication(user=user,
                                               application=application)
            user_application.save()

    context = {'application': application, 'form': form}
    return render(request, 'application-detail.html', context)
Пример #6
0
    def post(self, request):

        password = request.data["password"]
        email = request.data["username"]
        email = email.lower()
        username = email

        if UserModel.objects.filter(email=email):
            # Email address belongs to registered user
            msg = "Email address belongs to registered user"
            return Response(msg, status=400)

        elif UserModel.objects.filter(username=username):
            # Email address belongs to registered user
            msg = "username belongs to registered user"
            return Response(msg, status=400)

        else:
            newUser = UserModel(username=email,
                                email=email,
                                password=password,
                                is_active=True)
            newUser.set_password(newUser.password)
            newUser.save()

            new_UserInfo = UserInfo(user=newUser)
            new_UserInfo.save()

            user = authenticate(username=username, password=password)
            if user:
                django_login(request, user)
            else:
                msg = "error"
                return Response(msg, status=400)

            token, created = Token.objects.get_or_create(user=user)
            return Response({"token": token.key}, status=200)
Пример #7
0
 def test_comment_delete_permission_denied_to_non_moderator(self):
     req = RequestFactory().get('/')
     req.user = UserModel()
     req.user.is_moderator = False
     self.assertRaises(PermissionDenied, comment_delete, req)
Пример #8
0
    def mutate(self, info, username, password):
        new_user = UserModel(username=username, password=password)
        new_user.save()

        return RegisterUser(user=new_user)