def authorize_user(me, token=None): """ Return authorized user. Method saves user session cookies `user_id` """ user = User.get_or_init(me['login']) # update user data user.name = me.get('name', me.get('login')) user.github_access_token = token user.avatar = me['gravatar_id'] user.email = me['email'] # save to database db.session.add(user) db.session.commit() refresh_repositories.delay(user.login, token) return user
def me(): """ Bypass Github authentication and login as 1st user in the database. Usage: Visit /auth/me to log in as the 1st user in the database, to work offline as that user. To allow a github username to work in this single user mode, change GITAUTH_LOGIN_LIST config property. You need to login using GitHub at least once before this will work. This only works if server is in debug mode. """ if current_app.debug: # pylint:disable-msg=E1101 user = User.get_or_init('offline') if user.id and user.login in current_app.config['GITAUTH_LOGIN_LIST']: session['user_id'] = user.id g.user = user flash(_('Welcome to single user mode!')) return redirect(url_for('frontend.splash'))