예제 #1
0
파일: auth.py 프로젝트: shrx/Sedemnjastka
    def login(self):
        if request.method == 'POST':
            user = Session.query(User). \
                filter(User.nick_name==request.params['nick_name']) . \
                filter(User.password!=None).first()

            if user and bcrypt.hashpw(request.params['password'],
                                      user.password) == user.password:
                session['user'] = user
                session.save()
                if 'return_to' in session:
                    to = session['return_to']
                    del session['return_to']
                    session.save()
                    redirect(to)
                elif 'return_to' in request.params:
                    redirect(request.params['return_to'])
                else:
                    redirect('/')
            else:
                h.flash(
                    u'Sorči, to ni nobena kombinacija uporabniškega imena' +
                    'in gesla, ki bi bila meni znana.')

        c.title = 'prijava'
        return render('/auth/login.mako')
예제 #2
0
파일: users.py 프로젝트: shrx/Sedemnjastka
    def claim(self, id):
        c.user = Session.query(User).filter(User.id==id). \
            filter(User.password==None).first()
        if not c.user:
            abort(404)

        if request.method == 'POST':
            c.user.token = uuid.uuid4().get_hex()
            Session.add(c.user)
            Session.commit()

            mn3 = mn3njalnik.Mn3njalnik()
            try:
                mn3.login(config['mn3njalnik.username'],
                          config['mn3njalnik.password'])
                mn3.pm(
                    c.user.nick_name.encode('utf-8'),
                    'Polasti se svojega racuna se danes!', """
Oj, ti!

Svojega racuna na nasi strani http://sedemnajst.si se lahko polastis zdaj:

http://sedemnajst.si/users/passwd/%s

Lep pozdrav, in ostani vedno /17/
                       """ % c.user.token)
                h.flash(u'Imaš ZS—velik uspeh!')
            except:
                h.flash(u'Oh ne, nekaj je šlo napak.')

        c.title = u'polasti se svojega računa'
        return render('/users/claim.mako')
예제 #3
0
파일: auth.py 프로젝트: shrx/Sedemnjastka
    def login(self):
        if request.method == 'POST':
            user = Session.query(User). \
                filter(User.nick_name==request.params['nick_name']) . \
                filter(User.password!=None).first()

            if user and bcrypt.hashpw(request.params['password'],
                                      user.password) == user.password:
                session['user'] = user
                session.save()
                if 'return_to' in session:
                    to = session['return_to']
                    del session['return_to']
                    session.save()
                    redirect(to)
                elif 'return_to' in request.params:
                    redirect(request.params['return_to'])
                else:
                    redirect('/')
            else:
                h.flash(u'Sorči, to ni nobena kombinacija uporabniškega imena' +
                        'in gesla, ki bi bila meni znana.')

        c.title = 'prijava'
        return render('/auth/login.mako')
예제 #4
0
파일: users.py 프로젝트: shrx/Sedemnjastka
    def claim(self, id):
        c.user = Session.query(User).filter(User.id==id). \
            filter(User.password==None).first()
        if not c.user:
            abort(404)

        if request.method == 'POST':
            c.user.token = uuid.uuid4().get_hex()
            Session.add(c.user)
            Session.commit()

            mn3 = mn3njalnik.Mn3njalnik()
            try:
                mn3.login(config['mn3njalnik.username'],
                          config['mn3njalnik.password'])
                mn3.pm(c.user.nick_name.encode('utf-8'),
                       'Polasti se svojega racuna se danes!',
                       """
Oj, ti!

Svojega racuna na nasi strani http://sedemnajst.si se lahko polastis zdaj:

http://sedemnajst.si/users/passwd/%s

Lep pozdrav, in ostani vedno /17/
                       """ % c.user.token)
                h.flash(u'Imaš ZS—velik uspeh!')
            except:
                h.flash(u'Oh ne, nekaj je šlo napak.')

        c.title = u'polasti se svojega računa'
        return render('/users/claim.mako')
예제 #5
0
    def create(self):
        post = Session.query(Post). \
            filter(Post.id==int(request.params['post'])).first()

        quote = Quote(post, session['user'])
        Session.add(quote)
        Session.commit()
        Session.refresh(session['user'])

        h.flash('Uspeh')
        redirect(url('quote', id=quote.id))
예제 #6
0
    def new(self, post):
        c.post = Session.query(Post). \
            options(orm.joinedload(Post.avatar)). \
            get(post)
        if not c.post:
            abort(404)

        # quoted already?
        if c.post.quote != None:
            h.flash(u'Ta post je že v bazi navedkov, glej:')
            redirect(url('quote', id=c.post.quote.id))

        c.title = 'dodaj navedek'
        return render('/quotes/new.mako')
예제 #7
0
    def vote(self, id, way):
        quote = Session.query(Quote).filter(Quote.id==id).first()
        if not quote:
            abort(404)

        qv = QuoteVote(quote, session['user'], way == 'up')
        Session.add(qv)
        if way == 'up':
            quote.upvotes += 1
        elif way == 'down':
            quote.downvotes += 1
        Session.add(quote)
        Session.commit()
        Session.refresh(session['user'])

        h.flash(u'Tvoj glas smo zabeležili.')
        redirect(url('quote', id=quote.id))
예제 #8
0
파일: users.py 프로젝트: shrx/Sedemnjastka
    def passwd(self, token):
        c.user = Session.query(User).filter(User.token == token).first()
        if not c.user:
            abort(404)

        if request.method == 'POST':
            if request.params['passwd'] == request.params['passwd_confirm']:
                c.user.password = bcrypt.hashpw(request.params['passwd'],
                                                bcrypt.gensalt())
                c.user.token = None
                Session.add(c.user)
                Session.commit()
                h.flash(u'Uspeh—zdaj se lahko prijaviš.')
                redirect(url('login'))
            else:
                h.flash('Gesli se ne ujemata. :(')

        c.title = 'nastavi geslo'
        return render('/users/passwd.mako')
예제 #9
0
파일: users.py 프로젝트: shrx/Sedemnjastka
    def passwd(self, token):
        c.user = Session.query(User).filter(User.token==token).first()
        if not c.user:
            abort(404)

        if request.method == 'POST':
            if request.params['passwd'] == request.params['passwd_confirm']:
                c.user.password = bcrypt.hashpw(request.params['passwd'],
                                                bcrypt.gensalt())
                c.user.token = None
                Session.add(c.user)
                Session.commit()
                h.flash(u'Uspeh—zdaj se lahko prijaviš.')
                redirect(url('login'))
            else:
                h.flash('Gesli se ne ujemata. :(')

        c.title = 'nastavi geslo'
        return render('/users/passwd.mako')
예제 #10
0
    def guessed(self):
        user = Session.query(User). \
            get(request.params['user_id'])
        avatar = Session.query(Avatar). \
            get(request.params['avatar_id'])

        guessed = user.avatar.id == avatar.id
        if 'user' in session:
            avatar_guess = AvatarGuess(guessed, avatar, session['user'])
            Session.add(avatar_guess)
            Session.commit()
            Session.refresh(session['user'])
        else:
            avatar_guess = AvatarGuess(guessed, avatar)

        if 'ajax' in request.params:
            c.avatar_guess = avatar_guess
            return render('/guess-avatar/guessed-avatar.mako')
        else:
            if guessed: h.flash('Bravo, uganil/a si pravilno!')
            else: h.flash(u'Ne bo držalo.')
            redirect("/games/guess-avatar")
예제 #11
0
파일: users.py 프로젝트: shrx/Sedemnjastka
    def reset_passwd(self):
        if request.method == 'POST':
            user = Session.query(User). \
                filter(User.nick_name==request.params['nick_name']). \
                first()
            if user:
                user.token = uuid.uuid4().get_hex()
                Session.add(user)
                Session.commit()

                mn3 = mn3njalnik.Mn3njalnik()
                try:
                    mn3.login(config['mn3njalnik.username'],
                              config['mn3njalnik.password'])
                    mn3.pm(
                        user.nick_name.encode('utf-8'),
                        'Pozabljeno geslo? Ni problema!', """
Ojla, prijatelj!

Zahteval si ponastavitev svojega gesla na nasi strani: http://sedemnajst.si

To lahko storis sedaj, na naslednjem naslovu:

http://sedemnajst.si/users/passwd/%s

Ce te zahteve nisi sprozil sam, pa lahko to sporocilo brez skrbi ignoriras.

Lep pozdrav, in ostani vedno /17/
                           """ % user.token)
                    h.flash(u'Rečeno, storjeno—imaš ZS.')
                except:
                    h.flash(u'Oh ne, nekaj je šlo napak.')
            else:
                h.flash(u'Sori, uporabnik s takšnim imenom ne obstaja.')

        c.title = 'resetiraj geslo'
        return render('/users/reset-passwd.mako')
예제 #12
0
파일: users.py 프로젝트: shrx/Sedemnjastka
    def reset_passwd(self):
        if request.method == 'POST':
            user = Session.query(User). \
                filter(User.nick_name==request.params['nick_name']). \
                first()
            if user:
                user.token = uuid.uuid4().get_hex()
                Session.add(user)
                Session.commit()

                mn3 = mn3njalnik.Mn3njalnik()
                try:
                    mn3.login(config['mn3njalnik.username'],
                              config['mn3njalnik.password'])
                    mn3.pm(user.nick_name.encode('utf-8'),
                           'Pozabljeno geslo? Ni problema!',
                           """
Ojla, prijatelj!

Zahteval si ponastavitev svojega gesla na nasi strani: http://sedemnajst.si

To lahko storis sedaj, na naslednjem naslovu:

http://sedemnajst.si/users/passwd/%s

Ce te zahteve nisi sprozil sam, pa lahko to sporocilo brez skrbi ignoriras.

Lep pozdrav, in ostani vedno /17/
                           """ % user.token)
                    h.flash(u'Rečeno, storjeno—imaš ZS.')
                except:
                    h.flash(u'Oh ne, nekaj je šlo napak.')
            else:
                h.flash(u'Sori, uporabnik s takšnim imenom ne obstaja.')

        c.title = 'resetiraj geslo'
        return render('/users/reset-passwd.mako')
예제 #13
0
파일: users.py 프로젝트: shrx/Sedemnjastka
    def edit(self):
        c.user = session['user']
        if not c.user:
            abort(404)

        if request.method == 'POST':
            if 'new_passwd' in request.params:
                if bcrypt.hashpw(request.params['cur_passwd'],
                                 c.user.password) == c.user.password:
                    if request.params['new_passwd'] == request. \
                            params['new_passwd_confirm']:
                        c.user.password = \
                            bcrypt.hashpw(request.params['new_passwd'],
                                          bcrypt.gensalt())
                        Session.add(c.user)
                        Session.commit()
                        h.flash(u'Podatki so bili uspešno posodobljeni.')
                    else:
                        h.flash('Gesli se ne ujemata.')
                else:
                    h.flash(u'Napačno trenutno geslo.')

        c.title = 'uredi svoje podatke'
        return render('/users/edit.mako')
예제 #14
0
파일: users.py 프로젝트: shrx/Sedemnjastka
    def edit(self):
        c.user = session['user']
        if not c.user:
            abort(404)

        if request.method == 'POST':
            if 'new_passwd' in request.params:
                if bcrypt.hashpw(request.params['cur_passwd'],
                          c.user.password) == c.user.password:
                    if request.params['new_passwd'] == request. \
                            params['new_passwd_confirm']:
                        c.user.password = \
                            bcrypt.hashpw(request.params['new_passwd'],
                                          bcrypt.gensalt())
                        Session.add(c.user)
                        Session.commit()
                        h.flash(u'Podatki so bili uspešno posodobljeni.')
                    else:
                        h.flash('Gesli se ne ujemata.')
                else:
                    h.flash(u'Napačno trenutno geslo.')

        c.title = 'uredi svoje podatke'
        return render('/users/edit.mako')