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 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 "", }, )