def test_node(self): group = Group() group.name = "team1" group.screen_name = "team1" user1 = User() user1.name = "bob" user1.screen_name = "bob" group.create() user1.create() hoge = ModelC() hoge.node = group hoge.create() piyo = ModelC() piyo.node = user1 piyo.create() foo = ModelC() foo.node = group._id foo.create() bar= ModelC() bar.node = user1._id bar.create() self.assertEqual(hoge.node, group) self.assertEqual(piyo.node, user1) self.assertEqual(foo.node, group) self.assertEqual(bar.node, user1) pass
def test_user(self): user = User() user.name = "alice" user.screen_name = "alice" user.email = "*****@*****.**" user.set_password("alice_s_password_1234") user.create() self.assertTrue(User.password_auth("alice", "alice_s_password_1234")) jwt = user.get_jwt() self.assertEqual(User.check_jwt(jwt), user)
def test_group(self): group = Group() group.name = "team1" group.screen_name = "team1" user1 = User() user1.name = "bob" user1.screen_name = "bob" user1.email = "*****@*****.**" user2 = User() user2.name = "charlie" user2.screen_name = "charlie" user2.email = "*****@*****.**" group.create() user1.create() user2.create() group.append(user1) self.assertTrue(group.is_in(user1)) self.assertFalse(group.is_in(user2)) pass
def create(self, request): post = request.post() try: user = User() user.screen_name = post["screen_name"] user.name = post["name"] user.set_password(post["password"]) user.create() return Response.json(user.to_dict()) except KeyError as err: error = err return Response.json({ "error": err.__class__.__name__, "message": err.message, "args": err.args, })
def signup(self, request): sess = request.session() template = self.view.get_template("signup.html") invite = UserInvite.retrieve(token=request.query["token"][0]) if request.method == "POST": try: form = RegisterForm(request.post()) user = User() user.email = invite.email user.set_password(form["password"]) user.screen_name = form["screen_name"] user.name = form["name"] user.icon = (resize_icon(form["icon"]) if form["icon"] is not None else user.icon) user.create() sess["jwt_token"] = user.get_jwt() roles = invite.roles if len(roles) > 0: for role_id in invite.roles.split(":"): role = Role.retrieve(role_id) role.append(user) invite.delete() return Response.redirect(self.app.convert_url("/")) except (ValidationError, ValueError) as err: icon = form["icon"] return Response.render( template, { "error": err.messsage, "name": form["name"] or invite.name, "screen_name": (form["screen_name"] or invite.screen_name), "password": form["password"] or "", "icon": icon, }, ) return Response.render( template, { "icon": invite.icon, "name": invite.name or "", "screen_name": invite.screen_name or "", }, )