示例#1
0
文件: auth.py 项目: tracsa/cacahuate
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,
        }
    })
示例#2
0
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
示例#3
0
文件: utils.py 项目: tracsa/cacahuate
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