Beispiel #1
0
async def merchant(ctx):
    """Displays the daily Traveling merchant stock."""
    now2 = datetime.datetime.today()
    if now2.day == int(request.parse_stock_date()):
        now = datetime.datetime.now()
        member = ctx.message.author
        channel = ctx.message.channel
        server = ctx.message.server
        logger.info("called at " + now.strftime("%H:%M") +
                    ' by {0} in {1} of {2}'.format(member, channel, server))
        print("called at " + now.strftime("%H:%M") +
              ' by {0} in {1} of {2}'.format(member, channel, server))
        date_message = "The stock for " + now.strftime("%m/%d/%Y") + ":"
        await bot.send_file(ctx.message.channel,
                            output.output_img,
                            content=date_message)
        if not userdb.user_exists(ctx.message.author.id):
            print("user {0} doesn't have any preferences".format(
                ctx.message.author))
            chance = random.random()
            if chance < 0.1:
                await bot.say(
                    "Don't forget to try out the ?addnotif <item> function so you don't "
                    "have to check the stock every day!")
    else:
        await bot.say("The new stock isn't out yet!")
Beispiel #2
0
def check_auth_cookie(cookie_name):
    username, issue_time, cookie_hash = html.cookie(cookie_name,
                                                    '::').split(':', 2)

    # FIXME: Ablauf-Zeit des Cookies testen
    #max_cookie_age = 10
    #if float(issue_time) < time.time() - max_cookie_age:
    #    del_auth_cookie()
    #    return ''

    if not userdb.user_exists(username):
        raise MKAuthException(_('Username is unknown'))

    # Validate the hash
    serial = load_serial(username)
    if cookie_hash != generate_hash(username, issue_time, serial):
        raise MKAuthException(_('Invalid credentials'))

    # Once reached this the cookie is a good one. Renew it!
    renew_cookie(cookie_name, username, serial)

    if html.myfile != 'user_change_pw':
        result = userdb.need_to_change_pw(username)
        if result:
            html.http_redirect('user_change_pw.py?_origtarget=%s&reason=%s' %
                               (html.urlencode(html.makeuri([])), result))

    # Return the authenticated username
    return username
Beispiel #3
0
    def load(cls):
        cls.clear_instances()

        # First load builtin pages. Set username to ''
        for name, page_dict in cls.builtin_pages().items():
            page_dict["owner"] = ''  # might have been forgotten on copy action
            page_dict["public"] = True
            page_dict["name"] = name
            new_page = cls(page_dict)
            cls.add_instance(("", name), new_page)

        # Now scan users subdirs for files "user_$type_name.mk"
        subdirs = os.listdir(config.config_dir)
        for user in subdirs:
            try:
                path = "%s/%s/user_%ss.mk" % (config.config_dir, user,
                                              cls.type_name())
                if not os.path.exists(path):
                    continue

                if not userdb.user_exists(user):
                    continue

                user_pages = store.load_data_from_file(path, {})
                for name, page_dict in user_pages.items():
                    page_dict["owner"] = user
                    page_dict["name"] = name
                    cls.add_instance((user, name), cls(page_dict))

            except SyntaxError, e:
                raise MKGeneralException(
                    _("Cannot load %s from %s: %s") %
                    (cls.type_name(), path, e))
Beispiel #4
0
def check_auth_cookie(cookie_name):
    username, issue_time, cookie_hash = html.cookie(cookie_name, '::').split(':', 2)

    # FIXME: Ablauf-Zeit des Cookies testen
    #max_cookie_age = 10
    #if float(issue_time) < time.time() - max_cookie_age:
    #    del_auth_cookie()
    #    return ''

    if not userdb.user_exists(username):
        raise MKAuthException(_('Username is unknown'))

    # Validate the hash
    serial = load_serial(username)
    if cookie_hash != generate_hash(username, issue_time, serial):
        raise MKAuthException(_('Invalid credentials'))

    # Once reached this the cookie is a good one. Renew it!
    renew_cookie(cookie_name, username, serial)

    if html.myfile != 'user_change_pw':
        result = userdb.need_to_change_pw(username)
        if result:
            html.http_redirect('user_change_pw.py?_origtarget=%s&reason=%s' % (html.urlencode(html.makeuri([])), result))

    # Return the authenticated username
    return username
Beispiel #5
0
    def load(self):
        self.clear_instances()

        # First load builtin pages. Set username to ''
        for name, page_dict in self.builtin_pages().items():
            page_dict["owner"]  = '' # might have been forgotten on copy action
            page_dict["public"] = True
            page_dict["name"]   = name
            new_page = self(page_dict)
            self.add_instance(("", name), new_page)

        # Now scan users subdirs for files "user_$type_name.mk"
        subdirs = os.listdir(config.config_dir)
        for user in subdirs:
            try:
                path = "%s/%s/user_%ss.mk" % (config.config_dir, user, self.type_name())
                if not os.path.exists(path):
                    continue

                if not userdb.user_exists(user):
                    continue

                user_pages = eval(file(path).read())
                for name, page_dict in user_pages.items():
                    page_dict["owner"] = user
                    page_dict["name"] = name
                    self.add_instance((user, name), self(page_dict))

            except SyntaxError, e:
                raise MKGeneralException(_("Cannot load %s from %s: %s") %
                                                (self.type_name(), path, e))
Beispiel #6
0
def check_parsed_auth_cookie(username, issue_time, cookie_hash):
    if not userdb.user_exists(username):
        raise MKAuthException(_('Username is unknown'))

    serial = load_serial(username)
    if cookie_hash != generate_hash(username, issue_time, serial):
        raise MKAuthException(_('Invalid credentials'))

    return serial
Beispiel #7
0
    def rfid_scanned(self, code):
        if self._state == RELOCK:
            self.await_rfid()

        log.debug("rfid code: %s", code)

        if self._state == AWAIT_RFID:
            self._rfid = code
            self.await_pin()
        elif self._state == ADD_KEY:
            if not userdb.user_exists(self._dbconn, code):
                self._rfid = code
                self.add_key_pin_new()
            else:
                self.denied()
        elif self._state == RESET_PIN:
            self._rfid = code
            self.pinchange_new()
Beispiel #8
0
    def rfid_scanned(self, code):
        if self._state == RELOCK:
            self.await_rfid()

        log.debug("rfid code: %s", code)

        if self._state == AWAIT_RFID:
            self._rfid = code
            self.await_pin()
        elif self._state == ADD_KEY:
            if not userdb.user_exists(self._dbconn, code):
                self._rfid = code
                self.add_key_pin_new()
            else:
                self.denied()
        elif self._state == RESET_PIN:
            self._rfid = code
            self.pinchange_new()
Beispiel #9
0
def studentlogin():
    if request.method == "POST":
        last_name = str(request.form['last_name'])
        sid = request.form['sid']
        # If sid is NaN, then immediately kill. Kill it with fire.
        try:
            sid = int(sid)
        except:
            flash("Invalid 4-digit ID", "danger")
        # Check if valid user
        if userdb.user_exists(last_name, sid):
            session['logged_in'] = True         # Set logged in to True
            session['last_name'] = last_name    # Set last_name variable
            session['sid'] = sid                # Set sid variable
            return redirect(url_for("student_check"))
        else:
            flash("Unknown User", "danger")
    return render_template("student_login.html")
Beispiel #10
0
def studentlogin():
    if request.method == "POST":
        last_name = str(request.form['last_name'])
        sid = request.form['sid']
        # If sid is NaN, then immediately kill. Kill it with fire.
        try:
            sid = int(sid)
        except:
            flash("Invalid 4-digit ID", "danger")
        # Check if valid user
        if userdb.user_exists(last_name, sid):
            session['logged_in'] = True  # Set logged in to True
            session['last_name'] = last_name  # Set last_name variable
            session['sid'] = sid  # Set sid variable
            return redirect(url_for("student_check"))
        else:
            flash("Unknown User", "danger")
    return render_template("student_login.html")
Beispiel #11
0
def check_auth_cookie(cookie_name):
    username, issue_time, cookie_hash = html.cookie(cookie_name, '::').split(':', 2)

    # FIXME: Ablauf-Zeit des Cookies testen
    #max_cookie_age = 10
    #if float(issue_time) < time.time() - max_cookie_age:
    #    del_auth_cookie()
    #    return ''

    if not userdb.user_exists(username):
        raise MKAuthException(_('Username is unknown'))

    # Validate the hash
    serial = load_serial(username)
    if cookie_hash != generate_hash(username, issue_time, serial):
        raise MKAuthException(_('Invalid credentials'))

    # Once reached this the cookie is a good one. Renew it!
    renew_cookie(cookie_name, username, serial)

    # Return the authenticated username
    return username
Beispiel #12
0
def check_parsed_auth_cookie(username, issue_time, cookie_hash):
    if not userdb.user_exists(username):
        raise MKAuthException(_('Username is unknown'))

    if cookie_hash != generate_auth_hash(username, issue_time):
        raise MKAuthException(_('Invalid credentials'))