コード例 #1
0
 def setUpClass(self):
     u = User.objects(username="******", password="******")
     if len(u) > 0:
         u.delete()
     u = User()
     u.username = "******"
     u.password = "******"
     u.save()
     self.user = u
     now = datetime.datetime.now()
     r = Reservation.get_between(now, now + datetime.timedelta(days=1))
     r.delete()
コード例 #2
0
def register_user():
    data = request.get_data()
    data = json.loads(data)
    username = data['username']
    password = data['password']
    users = User.objects(username=username, password=password)
    if len(users) > 0:
        return jsonify({'id': -1}), 409
    else:
        user = User()
        user.username = username
        user.password = password
        user.privilege = 0
        user.save()
        return jsonify(user.get_dict()), 201
コード例 #3
0
def authorized(oauth_token):
    next_url = request.args.get('next') or url_for('index')
    if oauth_token is None:
        flash("Authorization failed.")
        return redirect(next_url)

    session['oauth_token'] = oauth_token

    me = github.get('user')
    user_id = me['login']

    user = User.query.filter_by(id=user_id).first()
    if user is None:
        user = User(id=user_id, uid=user_id, name=me['name'], source='github')

    user.last_login = DateUtil.now_datetime()
    user.save()

    RequestUtil.login(session, user_id)

    return redirect(next_url)