예제 #1
0
파일: app.py 프로젝트: jie/sportsapp
def oauth2_code_callback(oauth_port):
    code = flask.request.args.get('code')
    oauth_adapter = OauthAdapter(
        oauth_port,
        flask.current_app.config['OAUTH2_CONFIG'],
        mock=MOCK_MODE
    )
    oauth_adapter.client.get_access_token(code)
    userinfo = oauth_adapter.client.get_userinfo()
    user = User.fetchone(
        oauth_id=userinfo.oauth_id,
        oauth_type=userinfo.oauth_type
    )

    if not user:
        user = User()
        user.oauth_id = userinfo.oauth_id
        user.oauth_type = userinfo.oauth_type

    user.nickname = userinfo.nickname
    user.avatar = userinfo.avatar
    user.oauth_id = userinfo.oauth_id
    user.oauth_type = userinfo.oauth_type
    user.save()
    session_token = account_signin(user.to_dict())
    response = flask.make_response(flask.redirect(flask.url_for('index')))
    response.set_cookie('session_token', session_token['token'])
    return response
예제 #2
0
파일: app.py 프로젝트: jie/sportsapp
def signin_api():
    email = flask.request.form.get('email')
    password = flask.request.form.get('password')

    user = User.fetchone(email=email)
    if not user:
        raise error.UserNotExist()

    if user.password != utils.hash_password(password):
        raise error.UserPasswordError()

    return account_signin(user.to_dict())
예제 #3
0
파일: app.py 프로젝트: jie/sportsapp
def userinfo():
    user_id = flask.session['user_id']
    user = User.fetchone(pk=user_id)
    if flask.request.method == 'POST':
        nickname = flask.request.form.get('nickname')
        email = flask.request.form.get('email')
        password = flask.request.form.get('password')
        password_repeat = flask.request.form.get('password_repeat')

        result = User.checkUserinfo(user_id, nickname, email, password)
        if result and user.nickname == nickname:
            raise error.UserNicknameRegisted()
        elif result and user.email == email:
            raise error.UserEmailRegisted()
        else:
            user.nickname = nickname
            user.email = email
            user.status = const.UserStatus.OK
            if password == password_repeat:
                user.set_password(password)
        user.save()
    user_dict = user.to_dict()
    flask.session['userinfo'] = user_dict
    return user_dict
예제 #4
0
파일: app.py 프로젝트: jie/sportsapp
def index():
    if flask.session.get('user_id'):
        user = User.fetchone(pk=flask.session['user_id'], is_enable=1)
    else:
        user = None
    return flask.render_template('index.html', user=user)