Exemplo n.º 1
0
 def run(self, message):
     logging.info("Received Presence Message: {}".format(message))
     user = Admin(id=message["tags"]["user_id"])
     user.in_office = message["fields"]["value"]
     user.save()
     disp = "arrived" if user.in_office else "departed"
     post_slack.delay(message={"text": "{} has {}".format(user.name, disp)})
Exemplo n.º 2
0
 def run(self, message):
     logging.info("Received Presence Message: {}".format(message))
     user = Admin(id=message['tags']['user_id'])
     user.in_office = message['fields']['value']
     user.save()
     disp = "arrived" if user.in_office else "departed"
     post_slack.delay(message={"text": "{} has {}".format(user.name, disp)})
Exemplo n.º 3
0
 def presence_stream(self, body, msg):
     current = self.ws.handler.active_client
     a = Admin(id=body['tags']['user_id'])
     a.in_office = body['fields']['value']
     user = a.json()
     user['times'] = a.get_punchcard(self.INFLUX)
     body['user'] = user
     self.sendto({'event':'presence', '_to':current.address, 'data':body})
     return True
Exemplo n.º 4
0
    def post(self):
        form = request.form
        un = form['username']
        pw = form['password']
        nex = form.get('next', url_for("dashboard.index"))
        logging.info("Next: {}".format(nex))
        if not config.LDAP_LOGIN:
            a = Admin.find_one({'email': un})
            if a and a.verify_pwd(pw):
                login_user(a)
                logging.info("logged in")
                return redirect(nex)
            else:
                flash("Please try again", "danger")

        else:
            try:
                user = ldap_login(un, pw)
                a = Admin.find_one({'email': user.get('mail')[0]})
                if not a: a = Admin()
                a.name = user.get('displayName')[0]
                a.email = user.get('mail')[0]
                a.last_login = datetime.utcnow()
                a.save()
                rem = False
                if form.get("remember-me"): rem = True
                success = login_user(a, remember=rem)
                return redirect(nex)
            except Exception as e:
                logging.exception(e)
                flash("Please try again", "danger")

        return render_template("auth/login.html", form=form)
Exemplo n.º 5
0
 def presence_stream(self, body, msg):
     current = self.ws.handler.active_client
     a = Admin(id=body['tags']['user_id'])
     a.in_office = body['fields']['value']
     user = a.json()
     user['times'] = a.get_punchcard(self.INFLUX)
     body['user'] = user
     self.sendto({
         'event': 'presence',
         '_to': current.address,
         'data': body
     })
     return True
Exemplo n.º 6
0
    def post(self):
        form = request.form
        un = form['username']
        pw = form['password']
        nex = form.get('next', url_for("dashboard.index"))
        logging.info("Next: {}".format(nex))
        if not config.LDAP_LOGIN:
            a = Admin.find_one({'email':un})
            if a and a.verify_pwd(pw):
                login_user(a)
                logging.info("logged in")
                return redirect(nex)
            else:
                flash("Please try again", "danger")

        else:
            try:
                user = ldap_login(un, pw)
                a = Admin.find_one({'email':user.get('mail')[0]})
                if not a: a = Admin()
                a.name = user.get('displayName')[0]
                a.email = user.get('mail')[0]
                a.last_login = datetime.utcnow()
                a.save()
                rem = False
                if form.get("remember-me"): rem = True
                success = login_user(a, remember=rem)
                return redirect(nex)
            except Exception as e:
                logging.exception(e)
                flash("Please try again", "danger")

        return render_template("auth/login.html", form=form)
Exemplo n.º 7
0
 def load_user(self, id):
     try:
         logging.info("Loading User: {}".format(id))
         a = Admin(id=id)
         return a
     except Exception as e:
         logging.exception(e)
         return None
Exemplo n.º 8
0
    def post(self):
        form = request.form
        pwd = form['password']
        cpwd = form['confirm_password']
        if not Admin.passwords_match(pwd, cpwd):
            flash("Passwords do not match", "danger")
            return render_template("auth/register.html", form=form)
        try:
            a = Admin()
            a.name = form['name']
            a.email = form['email']
            a.password = form['password']
            a.save()
        except DuplicateKeyError as e:
            logging.exception(e)
            flash("Email address already taken", "danger")
            return render_template("auth/register.html", form=form)

        login_user(a)
        return redirect(url_for("dashboard.index"))
Exemplo n.º 9
0
    def post(self):
        form = request.form
        pwd = form['password']
        cpwd = form['confirm_password']
        if not Admin.passwords_match(pwd, cpwd):
            flash("Passwords do not match", "danger")
            return render_template("auth/register.html", form=form)
        try:
            a = Admin()
            a.name = form['name']
            a.email = form['email']
            a.password = form['password']
            a.save()
        except DuplicateKeyError as e:
            logging.exception(e)
            flash("Email address already taken", "danger");
            return render_template("auth/register.html", form=form)

        login_user(a)
        return redirect(url_for("dashboard.index"))