Exemple #1
0
def repo(user, repo, n):

    admin = False

    if user == request.cookies.get('username'):
        admin = True

    github.check_repository(admin=admin, user=user, repo=repo)

    if n is 0:
        # print("n: " + str(n))
        repository_folder = "static/repository/" + user + "-" + repo
    else:
        # print("n: " + str(n))
        repository_folder = github.download_file_repository(user=user,
                                                            repo=repo)

    readme_path = repository_folder + "/README.md"
    project_path = repository_folder + "/project.org"

    repo_dict = github.get('repos/' + user + '/' + repo)
    contents_dict = github.get('repos/' + user + '/' + repo + '/contents')
    collaborators_dict = github.get('repos/' + user + '/' + repo +
                                    '/collaborators')
    events_dict = github.get('repos/' + user + '/' + repo + '/events')

    with open(readme_path, "r") as f:
        readme_content = f.readlines()

    readme_content = ''.join(readme_content)

    projects_dict = org.display(project_path)

    if admin:
        hook = github.exist_hook(user=user, repo=repo)
        return render_template('repository.html',
                               admin=admin,
                               repos=repo_dict,
                               contents=contents_dict,
                               collaborators=collaborators_dict,
                               events=events_dict,
                               readme=Markup(
                                   markdown.markdown(readme_content)),
                               projects=projects_dict,
                               hook=hook)

    else:
        hook = False
        return render_template('repository.html',
                               admin=admin,
                               repos=repo_dict,
                               contents=contents_dict,
                               collaborators=collaborators_dict,
                               events=events_dict,
                               readme=Markup(
                                   markdown.markdown(readme_content)),
                               projects=projects_dict,
                               hook=hook)
Exemple #2
0
def update_languages():
  repos = github.get('/users/michaelclark2/repos')
  languages = {}
  for repo in repos:
    r = github.get(repo['languages_url'])
    languages.update(r)

  lang_lines = []
  for key in languages.keys():
    lang_lines.append({key: languages[key]})
  return jsonify(lang_lines)
Exemple #3
0
def authorized(auth):
    resp={}
    success=0
    if auth == 'github':
        resp = github.authorized_response()
        if resp is None: 
            flash('You denied the request to sign in.')
            return redirect(request.args.get('next') or url_for('main.index'))
        session['github_token'] = (resp['access_token'], '')
        success=1
    if success == 1:
        me = github.get('user')
        user = User.query.filter_by(email=me.data['email']).first()
        if user is None:
            user = User(
                email=me.data['email'],
                username=me.data['login'],
                password=resp['access_token'],
                confirmed=True)
            db.session.add(user)
            db.session.commit()
            default_notebook = Notebook(
                title='Default', author_id=user.id)
            db.session.add(default_notebook)
            db.session.commit()
        elif user is not None:
            user.confirmed=True
            db.session.commit()
            login_user(user)
        return redirect(request.args.get('next') or url_for('main.index'))
 def get(self):
     args = self.reqparse.parse_args()
     response = github.get(args.url)
     content = base64.b64decode(response['content'])
     return responseResult({
             'content': content
         }), 201
Exemple #5
0
def authorized(auth):
    resp = {}
    success = 0
    if auth == 'github':
        resp = github.authorized_response()
        if resp is None:
            flash('You denied the request to sign in.')
            return redirect(request.args.get('next') or url_for('main.index'))
        session['github_token'] = (resp['access_token'], '')
        success = 1
    if success == 1:
        me = github.get('user')
        user = User.query.filter_by(email=me.data['email']).first()
        if user is None:
            user = User(email=me.data['email'],
                        username=me.data['login'],
                        password=resp['access_token'],
                        confirmed=True)
            db.session.add(user)
            db.session.commit()
            default_notebook = Notebook(title='Default', author_id=user.id)
            db.session.add(default_notebook)
            db.session.commit()
        elif user is not None:
            user.confirmed = True
            db.session.commit()
            login_user(user)
        return redirect(request.args.get('next') or url_for('main.index'))
Exemple #6
0
def github_authorized(oauth_token):
    if oauth_token is None:
        flash("Authorization failed.")
        return redirect(url_for('index'))

    session['oauth_token'] = oauth_token

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

    # is user exist
    user = User.query.get(user_id)

    if user is None:
        # not exist, add
        user = User(id=user_id)

    # update github user information
    user.last_login = DateUtil.now_datetime()
    user.name = me.get('name', user_id)
    user.location = me.get('location', '')
    user.avatar = me.get('avatar_url', '')

    user.save()

    RequestUtil.login_user(user.dict())

    return redirect(url_for('index'))
Exemple #7
0
def navigate():
    repo = request.args.get('repo')
    url = request.args.get('url')
    contents_dict = github.get('repos/' + request.cookies.get('username') +
                               '/' + repo + '/contents' + '/' + url)
    print('path: ' + 'repos/' + request.cookies.get('username') + '/' + repo +
          '/contents' + '/' + url)
    return jsonify(contents_dict)
Exemple #8
0
    def get(self, user, repo):
        response = github.get('repos/' + user + '/' + repo + '/branches')
        branchs = []
        for branch in response:
            branchs.append({
                'name': branch['name'],
                'sha': branch['commit']['sha']
            })

        return responseResult({'branchs': branchs}), 201
 def get(self):
     response = github.get('user')
     return responseResult({
             'account': {
                 'user' : response['login'],
                 'id'   : response['id'],
                 'name' : response['name'],
                 'pic'  : 'https://avatars3.githubusercontent.com/u/' + str(response['id']) + '?v=3&s=100',
                 'email': response['email']
             }
         }), 201
Exemple #10
0
    def get(self, user, repo, sha):
        args = self.reqparse.parse_args()
        fe = args.fe
        response = github.get('repos/' + user + '/' + repo + '/git/trees/' +
                              sha + '?recursive=1')
        files = []
        for tree in response['tree']:
            match = re.search(fe, tree['path'])
            if match is not None:
                files.append({'url': tree['url'], 'path': tree['path']})

        return responseResult({'files': files}), 201
Exemple #11
0
def user():
    user = github.get('user')

    print(user["email"])
    print(user["name"])

    if user["email"] == None or user["name"] == None:
        return redirect(url_for('user_missing_data'))

    redirect_to_index = render_template('user.html', user=user)
    cookie = app.make_response(redirect_to_index)
    cookie.set_cookie('username', user['login'])
    return cookie
 def get(self, user):
     response =  github.get('users/' + user + '/repos')
     repos = []
     for repo in response:
         repos.append(
             {
                 'name'   : repo['name'],
                 'private': repo['private']
             }
         )
     return responseResult({
             'repos': repos
         }), 201
    def get(self, user, repo):
        response = github.get('repos/' + user + '/' + repo + '/branches')
        branchs = []
        for branch in response:
            branchs.append(
                {
                    'name': branch['name'],
                    'sha' : branch['commit']['sha']
                }
            );

        return responseResult({
                'branchs': branchs
            }), 201
Exemple #14
0
 def get(self):
     response = github.get('user')
     return responseResult({
         'account': {
             'user':
             response['login'],
             'id':
             response['id'],
             'name':
             response['name'],
             'pic':
             'https://avatars3.githubusercontent.com/u/' +
             str(response['id']) + '?v=3&s=100',
             'email':
             response['email']
         }
     }), 201
    def get(self, user, repo, sha):
        args = self.reqparse.parse_args()
        fe = args.fe
        response = github.get('repos/' + user + '/' + repo + '/git/trees/' + sha + '?recursive=1' )
        files = []
        for tree in response['tree']:
            match = re.search(fe, tree['path'])
            if match is not None:
                files.append(
                    {
                        'url' : tree['url'],
                        'path': tree['path']
                    }
                )

        return responseResult({
                'files': files
            }), 201
Exemple #16
0
def authorized(oauth_token):
    next_url = request.args.get('next') or url_for('index_bp.index')
    if oauth_token is None:
        return redirect(next_url)

    # get the username
    gh_user = github.get('user?access_token='+oauth_token)
    username = gh_user['login']

    user = User.query.filter_by(github_access_token=oauth_token,
                                username=username).first()
    if user is None:
        user = User(username, oauth_token)
        db_session.add(user)

    user.github_access_token = oauth_token
    db_session.commit()
    session['user_id'] = user.id
    return redirect(next_url)
def authorized(auth):
    resp = {}
    success = 0
    if auth == 'github':
        resp = github.authorized_response()
        if resp is None:
            flash('You denied the request to sign in.')
            return redirect(request.args.get('next') or url_for('main.index'))
        session['github_token'] = (resp['access_token'], '')
        success = 1
    if success == 1:
        me = github.get('user')
        user = Query(User).equal_to('email', me.data['email']).find()
        if not user:
            user = User.register(me.data['email'], me.data['login'],
                                 resp['access_token'])
            Notebook.create_default_notebook(user.id)
        else:
            user = user[0]
        login_user(user)
        return redirect(request.args.get('next') or url_for('main.index'))
Exemple #18
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)
Exemple #19
0
def github_oauth_handler(response):
    next_url = request.args.get('next') or url_for('app.index')

    if response is None or not response.get('access_token'):
        flash(u'You denied the request to sign in')
        return redirect(next_url)

    session['github_accesstoken'] = response.get('access_token')
    github_user = github.get('user').data

    user = User.query.filter(User.email == github_user.get('email')).first()
    if not user:
        # Create the user object if the user wasn't signed up.
        user = User(github_user.get('email'))
        db.session.add(user)
        db.session.commit()

        # Save the token for the user.
        github_accesstoken = GithubAccessToken(
            user.id,
            github_user.get('token_type'),
            github_user.get('scope'),
            github_user.get('access_token'),
        )
        db.session.add(github_accesstoken)
        db.session.commit()
    else:
        # Get the access token and change it.
        github_accesstoken = user.github_accesstoken
        github_accesstoken.token_type = github_user.get('token_type')
        github_accesstoken.scope = github_user.get('scope')
        github_accesstoken.access_token = github_user.get('access_token')

    login_user(github_accesstoken.user)

    return redirect(next_url)
Exemple #20
0
def github_oauth_handler(response):
    next_url = request.args.get('next') or url_for('app.index')

    if response is None or not response.get('access_token'):
        flash(u'You denied the request to sign in')
        return redirect(next_url)

    session['github_accesstoken'] = response.get('access_token')
    github_user = github.get('user').data

    user = User.query.filter(User.email == github_user.get('email')).first()
    if not user:
        # Create the user object if the user wasn't signed up.
        user = User(github_user.get('email'))
        db.session.add(user)
        db.session.commit()

        # Save the token for the user.
        github_accesstoken = GithubAccessToken(
            user.id,
            github_user.get('token_type'),
            github_user.get('scope'),
            github_user.get('access_token'),
        )
        db.session.add(github_accesstoken)
        db.session.commit()
    else:
        # Get the access token and change it.
        github_accesstoken = user.github_accesstoken
        github_accesstoken.token_type = github_user.get('token_type')
        github_accesstoken.scope = github_user.get('scope')
        github_accesstoken.access_token = github_user.get('access_token')

    login_user(github_accesstoken.user)

    return redirect(next_url)
Exemple #21
0
 def get_user_info(self):
     return github.get('user').data
Exemple #22
0
def login():
    # these parameters will be needed in multiple paths
    LDAP_ENABLED = True if 'LDAP_TYPE' in app.config.keys() else False
    LOGIN_TITLE = app.config[
        'LOGIN_TITLE'] if 'LOGIN_TITLE' in app.config.keys() else ''
    BASIC_ENABLED = app.config['BASIC_ENABLED']
    SIGNUP_ENABLED = app.config['SIGNUP_ENABLED']
    GITHUB_ENABLE = app.config.get('GITHUB_OAUTH_ENABLE')
    GOOGLE_ENABLE = app.config.get('GOOGLE_OAUTH_ENABLE')
    SAML_ENABLED = app.config.get('SAML_ENABLED')

    if g.user is not None and current_user.is_authenticated:
        return redirect(url_for('dashboard'))

    if 'google_token' in session:
        user_data = google.get('userinfo').data
        first_name = user_data['given_name']
        surname = user_data['family_name']
        email = user_data['email']
        user = User.query.filter_by(username=email).first()
        if not user:
            # create user
            user = User(username=email,
                        firstname=first_name,
                        lastname=surname,
                        plain_text_password=None,
                        email=email)
            user.create_local_user()

        session['user_id'] = user.id
        login_user(user, remember=False)
        session['external_auth'] = True
        return redirect(url_for('index'))

    if 'github_token' in session:
        me = github.get('user')
        user_info = me.data
        user = User.query.filter_by(username=user_info['name']).first()
        if not user:
            # create user
            user = User(username=user_info['name'],
                        plain_text_password=None,
                        email=user_info['email'])
            user.create_local_user()

        session['user_id'] = user.id
        session['external_auth'] = True
        login_user(user, remember=False)
        return redirect(url_for('index'))

    if request.method == 'GET':
        return render_template('login.html',
                               github_enabled=GITHUB_ENABLE,
                               google_enabled=GOOGLE_ENABLE,
                               saml_enabled=SAML_ENABLED,
                               ldap_enabled=LDAP_ENABLED,
                               login_title=LOGIN_TITLE,
                               basic_enabled=BASIC_ENABLED,
                               signup_enabled=SIGNUP_ENABLED)

    # process login
    username = request.form['username']
    password = request.form['password']
    otp_token = request.form.get('otptoken')
    auth_method = request.form.get('auth_method', 'LOCAL')

    # addition fields for registration case
    firstname = request.form.get('firstname')
    lastname = request.form.get('lastname')
    email = request.form.get('email')
    rpassword = request.form.get('rpassword')

    if None in [firstname, lastname, email]:
        #login case
        remember_me = False
        if 'remember' in request.form:
            remember_me = True

        user = User(username=username,
                    password=password,
                    plain_text_password=password)

        try:
            auth = user.is_validate(method=auth_method)
            if auth == False:
                return render_template('login.html',
                                       error='Invalid credentials',
                                       ldap_enabled=LDAP_ENABLED,
                                       login_title=LOGIN_TITLE,
                                       basic_enabled=BASIC_ENABLED,
                                       signup_enabled=SIGNUP_ENABLED,
                                       github_enabled=GITHUB_ENABLE,
                                       saml_enabled=SAML_ENABLED)
        except Exception, e:
            error = e.message['desc'] if 'desc' in e.message else e
            return render_template('login.html',
                                   error=error,
                                   ldap_enabled=LDAP_ENABLED,
                                   login_title=LOGIN_TITLE,
                                   basic_enabled=BASIC_ENABLED,
                                   signup_enabled=SIGNUP_ENABLED,
                                   github_enabled=GITHUB_ENABLE,
                                   saml_enabled=SAML_ENABLED)

        # check if user enabled OPT authentication
        if user.otp_secret:
            if otp_token:
                good_token = user.verify_totp(otp_token)
                if not good_token:
                    return render_template('login.html',
                                           error='Invalid credentials',
                                           ldap_enabled=LDAP_ENABLED,
                                           login_title=LOGIN_TITLE,
                                           basic_enabled=BASIC_ENABLED,
                                           signup_enabled=SIGNUP_ENABLED,
                                           github_enabled=GITHUB_ENABLE,
                                           saml_enabled=SAML_ENABLED)
            else:
                return render_template('login.html',
                                       error='Token required',
                                       ldap_enabled=LDAP_ENABLED,
                                       login_title=LOGIN_TITLE,
                                       basic_enabled=BASIC_ENABLED,
                                       signup_enabled=SIGNUP_ENABLED,
                                       github_enabled=GITHUB_ENABLE,
                                       saml_enabled=SAML_ENABLED)

        login_user(user, remember=remember_me)
        return redirect(request.args.get('next') or url_for('index'))
Exemple #23
0
def login():
    # these parameters will be needed in multiple paths
    LDAP_ENABLED = True if "LDAP_TYPE" in app.config.keys() else False
    LOGIN_TITLE = app.config["LOGIN_TITLE"] if "LOGIN_TITLE" in app.config.keys() else ""
    BASIC_ENABLED = app.config["BASIC_ENABLED"]
    SIGNUP_ENABLED = app.config["SIGNUP_ENABLED"]
    GITHUB_ENABLE = app.config.get("GITHUB_OAUTH_ENABLE")

    if g.user is not None and current_user.is_authenticated:
        return redirect(url_for("dashboard"))

    if "github_token" in session:
        me = github.get("user")
        user_info = me.data
        user = User.query.filter_by(username=user_info["name"]).first()
        if not user:
            # create user
            user = User(username=user_info["name"], plain_text_password=gen_salt(7), email=user_info["email"])
            user.create_local_user()

        session["user_id"] = user.id
        login_user(user, remember=False)
        return redirect(url_for("index"))

    if request.method == "GET":
        return render_template(
            "login.html",
            github_enabled=GITHUB_ENABLE,
            ldap_enabled=LDAP_ENABLED,
            login_title=LOGIN_TITLE,
            basic_enabled=BASIC_ENABLED,
            signup_enabled=SIGNUP_ENABLED,
        )

    # process login
    username = request.form["username"]
    password = request.form["password"]
    otp_token = request.form.get("otptoken")
    auth_method = request.form.get("auth_method", "LOCAL")

    # addition fields for registration case
    firstname = request.form.get("firstname")
    lastname = request.form.get("lastname")
    email = request.form.get("email")
    rpassword = request.form.get("rpassword")

    if None in [firstname, lastname, email]:
        # login case
        remember_me = False
        if "remember" in request.form:
            remember_me = True

        user = User(username=username, password=password, plain_text_password=password)

        try:
            auth = user.is_validate(method=auth_method)
            if auth == False:
                return render_template(
                    "login.html",
                    error="Invalid credentials",
                    ldap_enabled=LDAP_ENABLED,
                    login_title=LOGIN_TITLE,
                    basic_enabled=BASIC_ENABLED,
                    signup_enabled=SIGNUP_ENABLED,
                )
        except Exception, e:
            error = e.message["desc"] if "desc" in e.message else e
            return render_template(
                "login.html",
                error=error,
                ldap_enabled=LDAP_ENABLED,
                login_title=LOGIN_TITLE,
                basic_enabled=BASIC_ENABLED,
                signup_enabled=SIGNUP_ENABLED,
            )

        # check if user enabled OPT authentication
        if user.otp_secret:
            if otp_token:
                good_token = user.verify_totp(otp_token)
                if not good_token:
                    return render_template(
                        "login.html",
                        error="Invalid credentials",
                        ldap_enabled=LDAP_ENABLED,
                        login_title=LOGIN_TITLE,
                        basic_enabled=BASIC_ENABLED,
                        signup_enabled=SIGNUP_ENABLED,
                    )
            else:
                return render_template(
                    "login.html",
                    error="Token required",
                    ldap_enabled=LDAP_ENABLED,
                    login_title=LOGIN_TITLE,
                    basic_enabled=BASIC_ENABLED,
                    signup_enabled=SIGNUP_ENABLED,
                )

        login_user(user, remember=remember_me)
        return redirect(request.args.get("next") or url_for("index"))
Exemple #24
0
def login():
    # these parameters will be needed in multiple paths
    LDAP_ENABLED = True if 'LDAP_TYPE' in app.config.keys() else False
    LOGIN_TITLE = app.config['LOGIN_TITLE'] if 'LOGIN_TITLE' in app.config.keys() else ''
    BASIC_ENABLED = app.config['BASIC_ENABLED']
    SIGNUP_ENABLED = app.config['SIGNUP_ENABLED']
    GITHUB_ENABLE = app.config.get('GITHUB_OAUTH_ENABLE')

    if g.user is not None and current_user.is_authenticated:
        return redirect(url_for('dashboard'))

    if 'github_token' in session:
        me = github.get('user')
        user_info = me.data
        user = User.query.filter_by(username=user_info['name']).first()
        if not user:
            # create user
            user = User(username=user_info['name'],
                        plain_text_password=random_password(7),
                        email=user_info['email'])
            user.create_local_user()

        session['user_id'] = user.id
        login_user(user, remember = False)
        return redirect(url_for('index'))

    if request.method == 'GET':
        return render_template('login.html',
            github_enabled=GITHUB_ENABLE,
            ldap_enabled=LDAP_ENABLED, login_title=LOGIN_TITLE,
            basic_enabled=BASIC_ENABLED, signup_enabled=SIGNUP_ENABLED)

    # process login
    username = request.form['username']
    password = request.form['password']
    otp_token = request.form['otptoken'] if 'otptoken' in request.form else None
    auth_method = request.form['auth_method'] if 'auth_method' in request.form else 'LOCAL'

    # addition fields for registration case
    firstname = request.form['firstname'] if 'firstname' in request.form else None
    lastname = request.form['lastname'] if 'lastname' in request.form else None
    email = request.form['email'] if 'email' in request.form else None
    rpassword = request.form['rpassword'] if 'rpassword' in request.form else None

    if None in [firstname, lastname, email]:
        #login case
        remember_me = False
        if 'remember' in request.form:
            remember_me = True

        user = User(username=username, password=password, plain_text_password=password)

        try:
            auth = user.is_validate(method=auth_method)
            if auth == False:
                return render_template('login.html', error='Invalid credentials', ldap_enabled=LDAP_ENABLED, login_title=LOGIN_TITLE, basic_enabled=BASIC_ENABLED, signup_enabled=SIGNUP_ENABLED)
        except Exception, e:
            error = e.message['desc'] if 'desc' in e.message else e
            return render_template('login.html', error=error, ldap_enabled=LDAP_ENABLED, login_title=LOGIN_TITLE, basic_enabled=BASIC_ENABLED, signup_enabled=SIGNUP_ENABLED)

        # check if user enabled OPT authentication
        if user.otp_secret:
            if otp_token:
                good_token = user.verify_totp(otp_token)
                if not good_token:
                    return render_template('login.html', error='Invalid credentials', ldap_enabled=LDAP_ENABLED, login_title=LOGIN_TITLE, basic_enabled=BASIC_ENABLED, signup_enabled=SIGNUP_ENABLED)
            else:
                return render_template('login.html', error='Token required', ldap_enabled=LDAP_ENABLED, login_title=LOGIN_TITLE, basic_enabled=BASIC_ENABLED, signup_enabled=SIGNUP_ENABLED)

        login_user(user, remember = remember_me)
        return redirect(request.args.get('next') or url_for('index'))
Exemple #25
0
def user_missing_data():
    user = github.get('user')
    return render_template('user_missing_data.html', user=user)
Exemple #26
0
def login():
    # these parameters will be needed in multiple paths
    LDAP_ENABLED = True if 'LDAP_TYPE' in app.config.keys() else False
    LOGIN_TITLE = app.config[
        'LOGIN_TITLE'] if 'LOGIN_TITLE' in app.config.keys() else ''
    BASIC_ENABLED = app.config['BASIC_ENABLED']
    SIGNUP_ENABLED = app.config['SIGNUP_ENABLED']
    GITHUB_ENABLE = app.config.get('GITHUB_OAUTH_ENABLE')

    if g.user is not None and current_user.is_authenticated:
        return redirect(url_for('dashboard'))

    if 'github_token' in session:
        me = github.get('user')
        user_info = me.data
        user = User.query.filter_by(username=user_info['name']).first()
        if not user:
            # create user
            user = User(username=user_info['name'],
                        plain_text_password=gen_salt(7),
                        email=user_info['email'])
            user.create_local_user()

        session['user_id'] = user.id
        login_user(user, remember=False)
        return redirect(url_for('index'))

    if request.method == 'GET':
        return render_template('login.html',
                               github_enabled=GITHUB_ENABLE,
                               ldap_enabled=LDAP_ENABLED,
                               login_title=LOGIN_TITLE,
                               basic_enabled=BASIC_ENABLED,
                               signup_enabled=SIGNUP_ENABLED)

    # process login
    username = request.form['username']
    password = request.form['password']
    otp_token = request.form.get('otptoken')
    auth_method = request.form.get('auth_method', 'LOCAL')

    # addition fields for registration case
    firstname = request.form.get('firstname')
    lastname = request.form.get('lastname')
    email = request.form.get('email')
    rpassword = request.form.get('rpassword')

    if None in [firstname, lastname, email]:
        #login case
        remember_me = False
        if 'remember' in request.form:
            remember_me = True

        user = User(username=username,
                    password=password,
                    plain_text_password=password)

        try:
            auth = user.is_validate(method=auth_method)
            if auth == False:
                return render_template('login.html',
                                       error='Invalid credentials',
                                       ldap_enabled=LDAP_ENABLED,
                                       login_title=LOGIN_TITLE,
                                       basic_enabled=BASIC_ENABLED,
                                       signup_enabled=SIGNUP_ENABLED)
        except Exception as e:
            return render_template('login.html',
                                   error=e,
                                   ldap_enabled=LDAP_ENABLED,
                                   login_title=LOGIN_TITLE,
                                   basic_enabled=BASIC_ENABLED,
                                   signup_enabled=SIGNUP_ENABLED)

        # check if user enabled OPT authentication
        if user.otp_secret:
            if otp_token:
                good_token = user.verify_totp(otp_token)
                if not good_token:
                    return render_template('login.html',
                                           error='Invalid credentials',
                                           ldap_enabled=LDAP_ENABLED,
                                           login_title=LOGIN_TITLE,
                                           basic_enabled=BASIC_ENABLED,
                                           signup_enabled=SIGNUP_ENABLED)
            else:
                return render_template('login.html',
                                       error='Token required',
                                       ldap_enabled=LDAP_ENABLED,
                                       login_title=LOGIN_TITLE,
                                       basic_enabled=BASIC_ENABLED,
                                       signup_enabled=SIGNUP_ENABLED)

        login_user(user, remember=remember_me)
        return redirect(request.args.get('next') or url_for('index'))
    else:
        # registration case
        user = User(username=username,
                    plain_text_password=password,
                    firstname=firstname,
                    lastname=lastname,
                    email=email)

        # TODO: Move this into the JavaScript
        # validate password and password confirmation
        if password != rpassword:
            error = "Passsword and confirmation do not match"
            return render_template('register.html', error=error)

        try:
            result = user.create_local_user()
            if result == True:
                return render_template('login.html',
                                       username=username,
                                       password=password,
                                       ldap_enabled=LDAP_ENABLED,
                                       login_title=LOGIN_TITLE,
                                       basic_enabled=BASIC_ENABLED,
                                       signup_enabled=SIGNUP_ENABLED)
            else:
                return render_template('register.html', error=result)
        except Exception as e:
            return render_template('register.html', error=e)
Exemple #27
0
def events():
    link = 'users/' + request.cookies.get('username') + '/events'
    github.get(link)
    event_dict = github.get(link)
    return render_template('events.html', events=event_dict)
Exemple #28
0
def dashboard():
    repo_dict = github.get('user/repos')
    return render_template('dashboard.html', repos=repo_dict)
Exemple #29
0
def repos():
    repo_dict = github.get('user/repos')
    return render_template('repositories.html', repos=repo_dict)
Exemple #30
0
 def get(self, user):
     response = github.get('users/' + user + '/repos')
     repos = []
     for repo in response:
         repos.append({'name': repo['name'], 'private': repo['private']})
     return responseResult({'repos': repos}), 201
Exemple #31
0
 def get(self):
     args = self.reqparse.parse_args()
     response = github.get(args.url)
     content = base64.b64decode(response['content'])
     return responseResult({'content': content}), 201