예제 #1
0
    def render(self, template_name, data={}):
        """Renders the template in the site wide manner.

        Retrieves the template data needed for the base template (login URL and
        text, user information, etc.) and merges it with the data passed to the
        method. Templates are retrieved from the template directory specified
        in the settings and appended with the suffix ".html"

        Arguments:
        template_name: the name of the template. this is the file name of the
                       template without the .html extension.

        data: a dictionary containing data to be passed to the template.
        """
        (login_text, login_url) = auth.login_logout(self.request)

        if auth.logged_in():
            data['user'] = auth.User(auth.current_user())

        data['admin'] = auth.user_is_admin()
        data['login_url'] = login_url
        data['login_text'] = login_text
        data['messages'] = Messages.get()

        path = os.path.join(settings.BASE_DIR, settings.TEMPLATE_DIR,
                        "%s.html" % template_name)

        return self.response.out.write(template.render(path, data))
예제 #2
0
파일: login.py 프로젝트: saisha17/zoobar
def logged_in():
    g.user = auth.User()
    g.user.checkCookie(request.cookies.get("PyZoobarLogin"))
    if g.user.person:
        return True
    else:
        return False
예제 #3
0
 def signup(self):
     """Displays the group sign up form."""
     user = auth.User(auth.current_user())
     if user.in_group():
         Messages.add('You are already in a group')
         return self.redirect('/groups')
     else:
         return self.render('groups_signup')
예제 #4
0
    def leave(self, key):
        """Removes the current user from the group's roster."""
        group = Group.get(key)
        user = auth.User(auth.current_user())

        if user.group != group:
            Messages.add('You cannot leave a group you are not in')
            return self.redirect('/groups/%s' % key)

        group.members.remove(user.gae_user)
        group.put()
        return self.redirect('/groups')
예제 #5
0
 def claim(self, key):
     """Claims a project for a group."""
     user = auth.User(auth.current_user())
     group = user.group
     if group.owner.user_id() == auth.current_user().user_id():
         project = Project.get(key)
         group.project = project
         group.put()
         return self.redirect('/groups/%s' % group.key())
     else:
         Messages.add('You are not the owner of your group. Only the ' +
                      'owner of the group may select a project.')
         return self.redirect('/projects')
예제 #6
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    if request.method == 'GET':
        return render_template('login.html')
    elif request.method == 'POST':
        user = auth.User()
        if user.try_to_log_in_by_request(request):
            login_user(user)
            common.ensure_dir(user.get_dir())
            next = request.args.get('next')
            return redirect(next or url_for('index'))
        else:
            logout_user()
            return render_template('login.html', error_message='Wrong username or password.')
    return render_template('login.html')
예제 #7
0
 def join(self, key):
     """Adds the current user to the group's roster."""
     group = Group.get(key)
     user = auth.User(auth.current_user())
     if user.in_group():
         Messages.add('You are already in a group')
         return self.redirect('/groups/%s' % key)
     if user.pending_join():
         Messages.add('You have already applied to join a group')
         return self.redirect('/groups/%s' % key)
     if group.public:
         group.members.append(auth.current_user())
         Messages.add('You have joined the group')
     else:
         group.pending_users.append(auth.current_user())
         Messages.add('You have requested to join the group')
     group.put()
     return self.redirect('/groups/%s' % key)
예제 #8
0
파일: login.py 프로젝트: subhamg/mit_6858
def login():
    cookie = None
    login_error = ""
    user = auth.User()

    if request.method == 'POST':
        username = request.form.get('login_username')
        password = request.form.get('login_password')

        if 'submit_registration' in request.form:
            if not username:
                login_error = "You must supply a username to register."
            elif not password:
                login_error = "You must supply a password to register."
            else:
                cookie = user.addRegistration(username, password)
                log("This is Cookie:%s " % cookie)
                if not cookie:
                    login_error = "Registration failed."
        elif 'submit_login' in request.form:
            if not username:
                login_error = "You must supply a username to log in."
            elif not password:
                login_error = "You must supply a password to log in."
            else:
                cookie = user.checkLogin(username, password)
                log("This is: %s" % cookie)
                if not cookie:
                    login_error = "Invalid username or password."

    nexturl = request.values.get('nexturl', url_for('index'))
    if cookie:
        response = redirect(nexturl)
        response.set_cookie('PyZoobarLogin', cookie)
        return response

    return render_template('login.html',
                           nexturl=nexturl,
                           login_error=login_error,
                           login_username=Markup(
                               request.form.get('login_username', '')))
예제 #9
0
async def login(request):
    username = await authorized_userid(request)
    if username:
        return web.HTTPFound("/rooms")
    else:
        valid = False
        if request.method == 'POST':
            policy = app['AuthzPolicy']
            data = await request.post()
            username = data['username']
            password = data['password']
            form = {'username': username, 'password': password}
            if 'register' in data:
                if username in policy.user_map:
                    form['error'] = "Username already taken"
                elif not username:
                    form['error'] = "Please provide a username"
                elif not password:
                    form['error'] = "Please provide a password"
                else:
                    u = auth.User(username)
                    u.set_password(password)
                    policy.user_map[username] = u
                    app['AuthzPolicy'].save()
                    valid = True
            elif 'login' in data:
                if username not in policy.user_map or not policy.user_map[
                        username].check_password(password):
                    form['error'] = "Username and/or Password do not match"
                else:
                    valid = True
            if valid:
                response = web.HTTPFound("/rooms")
                await remember(request, response, username)
                return response
            return form
        else:
            return {'username': '', 'password': ''}
예제 #10
0
def login():
    if fl.request.method == 'GET':
        return render_template(
            'login.html',
            'Login',
            message='Welcome to the EGCG Reporting App. Log in here.',
            redirect=quote(fl.request.args.get('redirect', ''), safe=())
        )

    username = fl.request.form['username']
    redirect = fl.request.form['redirect']
    if auth.check_user_auth(username, fl.request.form['pw']):
        u = auth.User(username)
        flask_login.login_user(u, remember=True)
        app.logger.info("Logged in user '%s'", username)
        return fl.redirect(unquote(redirect))

    return render_template(
        'login.html',
        'Login',
        message='Bad login.',
        redirect=redirect
    )
예제 #11
0
def add_user(username, password, email, admin_rights):
    user = auth.User(username, password, email, admin_rights)
    auth.db.session.add(user)
    auth.db.session.commit()
예제 #12
0
import auth


def add_user(username, password, email, admin_rights):
    user = auth.User(username, password, email, admin_rights)
    auth.db.session.add(user)
    auth.db.session.commit()


if __name__ == '__main__':
    username = raw_input("Please give username: "******"Please give password: "******"Please give email: ")

    user = auth.User(username, password, email, False)
    auth.db.session.add(user)
    auth.db.session.commit()
예제 #13
0
def load_user(user_id):
    print('USER ID:', user_id)
    user = auth.User(user_id)
    return user.get()