def signin(backend): # this raises AuthenticationError exception if failed identifier, data = backend.authenticate(**flask.request.form.to_dict()) user = get_or_create_user(identifier, data) # creates auth token if user.tokens.count() > 0: token = user.tokens.all()[0] else: token = ''.join(choice(ascii_letters) for _ in range(32)) token = Token(token=token).save() token.user.set(user) return flask.jsonify({ 'data': { 'username': user.identifier, 'fullname': user.fullname, 'token': token.token, } })
def make_user(identifier, name): u = User(identifier=identifier, fullname=name).save() token = Token(token=random_string(9)).save() token.proxy.user.set(u) return u
def make_user(identifier, name, email=None): u = User(identifier=identifier, fullname=name, email=email).save() token = Token(token=random_string(9)).save() token.user.set(u) return u