Ejemplo n.º 1
0
 def get(self, id):
     """
     GET /confirm/id
     it allows to confirm an email address using the event id
     :return:
     """
     try:
         ev = yield r.table('activity').get(id).run(self.application.dbconnection)
         if len(ev) != 1:
             raise ValueError("event id is not valid")
         event = Event(ev)
         event.setPending()
         dispatch(self.application.dbconnection, event)
         event.logInfo("Event is pending, a manager will validate your request")
         self.finish(json.dumps({"result": ["your email is confirmed"]}, cls=myJSONEncoder))
     except Exception as e:
         self.userError("This link is not valid")
         return
Ejemplo n.º 2
0
 def get(self, id):
     msg = ""
     try:
         ev = yield r.table('activity').get(id).run(self.application.dbconnection)
         if ev is None:
             raise ValueError("event id is not valid")
         event = Event(ev)
         event.setPending()
         event.logInfo("Event is pending, a manager will validate your request")
         msg = "Your email is confirmed. "
         msg += "A request has been sent to a manager. "
         msg += "You will be informed as soon as your account will be validated."
         # dispatch the updated event
         dispatch(self.application.dbconnection, event)
     except Exception as e:
         import traceback
         traceback.print_exc()
         msg = "This link is not valid"
     self.render(self.application.templates + "/confirm.html", message=msg)
Ejemplo n.º 3
0
def run(q):
    """
    Manages newly created events
    """
    logger.info("Worker activity events starting")

    # db connection is shared between threads
    dbconnection = connect()

    while True:
        try:
            event = Event(q.get())
        except Exception as e:
            import traceback
            traceback.print_exc()
            logger.error("Problem with event: {}".format(e))
            event.logError("Error in worker activity: {}".format(e))
            event.setError()
            dispatch(dbconnection, event)
            continue
        else:
            logger.debug("%s - Manage event".format(event.id))
            # TODO: if event.creatingObject()
            # Check if the event.object.id already exists or not
            # if it exists -> add a numer to the id & hrn to make it unique

            if event.object.type == ObjectType.PASSWORD:
                try:
                    event.setPending()
                    event.logInfo("Event is pending, please check your email")
                    logger.debug("Event %s is pending" % event.id)
                except Exception as e:
                    logger.error(
                        "Error in processing Event (1): {}".format(event))
                    logger.error("Error while processing: {}".format(e))
                    event.logError(str(e))
                    continue

            # Register a new object for a new user
            # id should be generated into the web to avoid duplicates
            elif event.isNew() and event.object.type in [
                    ObjectType.USER, ObjectType.AUTHORITY
            ] and event.user is None and event.creatingObject():
                try:
                    # The user must confirm his/her email
                    logger.debug("Event Type: {}".format(type(event)))
                    event.setConfirm()
                    logger.debug("Event %s is confirm" % event.id)
                    event.logInfo(
                        "Event is expecting your confirmation, please check your email"
                    )
                except Exception as e:
                    logger.error(
                        "Error in processing Event (2): {}".format(event))
                    logger.error("Error while processing: {}".format(e))
                    event.logError(str(e))
                    continue

            else:
                try:
                    logger.debug("%s - get user %s" % (event.id, event.user))
                    db_user = db.get(dbconnection,
                                     table='users',
                                     id=event.user)
                    if db_user:
                        user = User(db_user)
                        logger.debug("%s - Does user %s has privilege?" %
                                     (event.id, event.user))
                        if user.has_privilege(event):
                            logger.debug("%s - setWaiting" % event.id)
                            event.logInfo("Event waiting to be processed")
                            event.setWaiting()
                        else:
                            logger.debug("%s - setPending" % event.id)
                            event.logInfo(
                                "your user has no rights on %s, event pending until approved"
                                % event.user)
                            event.setPending()
                    else:
                        event.setError()
                        logger.error("User {} not found in event {}".format(
                            event.user, event.id))
                        event.logError("User %s not found" % event.user)
                        # raising an Exception here, blocks the REST API
                        #raise Exception("User %s not found" % event.user)
                except Exception as e:
                    logger.error("Error processing Event")
                    logger.error(event)
                    import traceback
                    logger.error(traceback.print_exc())
                    traceback.print_exc()
                    event.setError()
                    event.logError(str(e))
                    logger.error("Unable to fetch the user {} from db".format(
                        event.user))
                    logger.exception(e)
                    continue

            # dispatch the updated event
            dispatch(dbconnection, event)