예제 #1
0
파일: handlers.py 프로젝트: ryanotron/mci
 def new_fn_rl(self, mID, *args, **kwargs):
     userid = self.request.cookies.get('userid')
     userid, user = utils.verify_user(userid)
     if user:
         fn(self, mID, user, *args, **kwargs)
     else:
         message = ['you must be logged in to see this page']
         utils.assign_session_message(self, mID, message)
         self.redirect('/login')
예제 #2
0
파일: handlers.py 프로젝트: ryanotron/mci
 def post(self, mID, user):
     seatN = self.request.get('seatN')
     db_seat = db.GqlQuery('select * from SeatModel where seatNumber = :1 limit 1', seatN)
     db_seat = list(db_seat)
     if not db_seat:
         message = ['there is no such seat']
         utils.assign_session_message(self, mID, message)
         self.redirect('/adminpanel')
     else:
         db_seat = db_seat[0]
         db_seat.status = 'reserved'
         db_seat.put()
         message = ['successfully released seat %s' % seatN]
         utils.assign_session_message(self, mID, message)
         self.redirect('/adminpanel')
예제 #3
0
파일: handlers.py 프로젝트: ryanotron/mci
 def post(self, mID, user):
     seatN = self.request.get('seatN')
     db_seat = db.GqlQuery('select * from SeatModel where seatNumber = :1 limit 1', seatN)
     logging.error(type(db_seat))
     logging.error(str(db_seat))
     db_seat = list(db_seat)
     logging.error(str(db_seat))
     if not db_seat:
         message = ['there is no such seat']
         utils.assign_session_message(self, mID, message)
         self.redirect('/adminpanel')
     else:
         db_seat = db_seat[0]
         db_seat.status = 'available'
         db_seat.taker = ''
         db_seat.takerEmail = ''
         db_seat.confNumber = ''
         db_seat.put()
         message = ['successfully released seat %s' % seatN]
         utils.assign_session_message(self, mID, message)
         self.redirect('/adminpanel')
예제 #4
0
파일: handlers.py 프로젝트: ryanotron/mci
 def post(self, mID):
     username = self.request.get('username')
     password = self.request.get('password')
     
     message = []
     
     if username and password:
         user = db.GqlQuery('select * from UserModel where username = :1 limit 1', username)
         user = list(user)
         if len(user) > 0:
             user = user[0]
             if utils.verify_password(username, password, user.hashedpw):
                 userid = str(user.key().id())
                 self.response.headers.add_header('Set-Cookie', 'userid=%s; Path=/' % utils.securify_cookie(userid))
                 self.redirect('/adminpanel')
             else:
                 logging.error('wrong password')
                 message.append('wrong password')
                 utils.assign_session_message(self, mID, message)
                 self.redirect('/login')
         else:
             logging.error('no such user')
             message.append('no such user')
             utils.assign_session_message(self, mID, message)
             self.redirect('/login')
     else:
         message.append('fill both fields')
         utils.assign_session_message(self, mID, message)
         self.redirect('/login')
예제 #5
0
파일: handlers.py 프로젝트: ryanotron/mci
 def post(self, mID, user):
     ###add login requirement
     seatN  = self.request.get('seatN')
     seatL  = self.request.get('seatL')
     status = self.request.get('status')
     
     if not status:
         status = 'available'
         
     seat = models.SeatModel(seatNumber   = seatN,
                             seatLocation = seatL,
                             status       = status)
     seat.put()
     
     message = []
     message.append("Successfully added seat %s at %s with status %s" % (seatN, seatL, status))
     
     # mID = self.request.cookies.get('mID')
     # mID = utils.verify_cookie(mID)
     
     utils.assign_session_message(self, mID, message)
     self.redirect('/adminpanel')
예제 #6
0
파일: handlers.py 프로젝트: ryanotron/mci
 def post(self, mID, user):
     if not user.rank == 'patrician':
         message = ['You are a plebeian! What the f**k are you doing here?']
         utils.assign_session_message(self, mID, message)
         self.redirect('/')
     else:
         adminkey = self.request.get('adminkey');
         rank     = self.request.get('rank');
         if not rank in ['patrician', 'plebeian']:
             message = ['Are you trying to bring a barbarian here!?']
             utils.assign_session_message(self, mID, message)
             self.redirect('/adminpanel')
         else:
             new_adminkey = models.AdminkeyModel(adminkey = adminkey,
                                                 rank     = rank,
                                                 used     = False)
             new_adminkey.put()
             message = ['successfully added key %s' % adminkey]
             utils.assign_session_message(self, mID, message)
             self.redirect('/adminpanel')
예제 #7
0
파일: handlers.py 프로젝트: ryanotron/mci
    def post(self, mID):
        username = self.request.get('username')
        password = self.request.get('password')
        verify   = self.request.get('verify')
        adminkey = self.request.get('adminkey')

        admins = db.GqlQuery('select * from UserModel')
        admins = list(admins)
        
        message = []
        
        if username:
            valid = constants.username_re.match(username)
            if valid:
                taken = False
                for admin in admins:
                    if admin.username == username:
                        message.append('Username is taken. Choose another one')
                        utils.assign_session_message(self, mID, message)
                        taken = True
                        break
                if taken:
                    loggine.error('name taken')
                    self.redirect('/signup')
                else:
                    valid_pw = constants.password_re.match(password)
                    if valid_pw and password == verify:
                        if len(admins) < 1:
                            logging.error('added first admin')
                            new_admin = models.UserModel(username = username,
                                                         hashedpw = utils.securify_password(username, password),
                                                         nameday  = datetime.datetime.now(),
                                                         rank     = 'patrician')
                            new_admin.put()
                            message.append('Successfully registered as %s' % username)
                            utils.assign_session_message(self, mID, message)
                            self.redirect('/login')
                        else:
                            adminkeys = db.GqlQuery('select * from AdminkeyModel')
                            adminkeys = list(adminkeys)
                            valid_key = False
                            db_key = None
                            for key in adminkeys:
                                if key.adminkey == adminkey and key.used == False:
                                    valid_key = True
                                    db_key = key
                                    break
                            if valid_key:
                                db_key.used = True
                                db_key.dateused = datetime.datetime.now()
                                
                                new_admin = models.UserModel(username = username,
                                                             hashedpw = utils.securify_password(username, password),
                                                             nameday  = datetime.datetime.now(),
                                                             rank     = db_key.rank)
                                new_admin.put()
                                db_key.put()
                                logging.error('added regular admin')
                                message.append('Successfully registered as %s' % username)
                                utils.assign_session_message(self, mID, message)
                                self.redirect('/login')
                            else:
                                logging.error('invalid key')
                                message.append('invalid key')
                                utils.assign_session_message(self, mID, message)
                                self.redirect('/signup')
                    else:
                        logging.error('password verification failed')
                        message.append('Password verification failed')
                        utils.assign_session_message(self, mID, message)
            else:
                logging.error('invalid username')
                message.append('Username is not valid. Choose another one')
                utils.assign_session_message(self, mID, message)
                self.redirect('/signup')
        else:
            logging.error('no name')
            message.append('Choose a name')
            utils.assign_session_message(self, mID, message)
            self.redirect('/signup')
예제 #8
0
파일: handlers.py 프로젝트: ryanotron/mci
    def post(self, mID):
        taker = self.request.get('taker')
        email = self.request.get('email')
        seatN = self.request.get('seatN')
        
        seats = db.GqlQuery('select * from SeatModel where seatNumber = :1', seatN)
        seats = list(seats)
        logging.error(len(seats))
        message = []
        
        if len(seats) < 1:
            #invalid seat number
            logging.error('invalid seat number')
            message.append('That seat number is invalid. Choose another one')
            utils.assign_session_message(self, mID, message)
            self.redirect('/ticket')
        else:        
            seat = seats[0]
            if not seat.status == 'available':
                #seat is not available
                message = []
                message.append('Seat %s is not available. Choose another one' % seatN)
                utils.assign_session_message(self, mID, message)
                self.redirect('/ticket')
            else:
                if not taker:
                    message.append('What is your name?')
                if not email:
                    message.append('You must provide an email')
                if not taker or not email:
                    utils.assign_session_message(self, mID, message)
                    self.redirect('/ticket')
                else:
                    valid = constants.email_re.match(email)
                    if not valid:
                        message = ['invalid email!']
                        utils.assign_session_message(self, mID, message)
                        self.redirect('/ticket')
                    else:
                        seat.taker = taker
                        seat.takerEmail = email
                        seat.dateTaken = datetime.datetime.now()
                        seat.confNumber = hashlib.md5(taker + email + seatN).hexdigest().upper()
                        seat.status = 'taken'
                        seat.put()
                        
                        message = []
                        message.append('Successfully booked seat %s' % seatN)
                        utils.assign_session_message(self, mID, message)
                        
                        sender = '*****@*****.**'
                        to = email
                        subject = 'Your Malam Cinta Indonesia Ticket'
                        body = """
                                Hello %s,
                                You have successfully booked a seat for Malam Cinta Indonesia 2013. Here is your booking information:
                                Registration name: %s
                                Seat number: %s
                                Confirmation number: %s

                                You can show this email to our staff at the night of the event to gain entry into the venue.

                                See you there!""" % (taker, taker, seatN, seat.confNumber)
                        mail.send_mail(sender, to, subject, body)
                        
                        self.redirect('/')
예제 #9
0
파일: handlers.py 프로젝트: ryanotron/mci
 def post(self, mID, user):
     utils.reset_seats()
     message = ['successfully reset all seats']
     utils.assign_session_message(self, mID, message)
     self.redirect('/adminpanel')
예제 #10
0
파일: handlers.py 프로젝트: ryanotron/mci
 def get(self, mID):
     self.response.headers.add_header('Set-Cookie', 'userid=; Path=/')
     message = ['successfully logged out']
     utils.assign_session_message(self, mID, message)
     self.redirect('/')