def decorated_function(*args, **kwargs):
            errorMessage = "Login Required"
            if LoginSession.isLogin(session):
                userDb = UserHandler()
                try:
                    user = userDb.getUserByUID(session["name"])
                    validUser = True
                    for permission in permissionList:
                        if not userDb.hasPermission(user, permission):
                            validUser = False
                finally:
                    InterfaceHolder.closeOne(userDb)
                if validUser:
                    return f(*args, **kwargs)
                errorMessage = "Wrong User Type"
            elif "check_email_token" in permissionList:
                if LoginSession.isRegistering(session):
                    return f(*args, **kwargs)
                else:
                    errorMessage = "unauthorized"
            elif "check_password_token" in permissionList:
                if LoginSession.isResetingPassword(session):
                    return f(*args, **kwargs)
                else:
                    errorMessage = "unauthorized"

            returnResponse = flask.Response()
            returnResponse.headers["Content-Type"] = "application/json"
            returnResponse.status_code = 401  # Error code
            responseDict = {}
            responseDict["message"] = errorMessage
            returnResponse.set_data(json.dumps(responseDict))
            return returnResponse
Exemplo n.º 2
0
        def decorated_function(*args, **kwargs):
            errorMessage = "Login Required"
            if LoginSession.isLogin(session):
                userDb = UserHandler()
                try:
                    user = userDb.getUserByUID(session["name"])
                    validUser = True
                    for permission in permissionList:
                        if (not userDb.hasPermission(user, permission)):
                            validUser = False
                finally:
                    InterfaceHolder.closeOne(userDb)
                if (validUser):
                    return f(*args, **kwargs)
                errorMessage = "Wrong User Type"
            elif "check_email_token" in permissionList:
                if (LoginSession.isRegistering(session)):
                    return f(*args, **kwargs)
                else:
                    errorMessage = "unauthorized"
            elif "check_password_token" in permissionList:
                if (LoginSession.isResetingPassword(session)):
                    return f(*args, **kwargs)
                else:
                    errorMessage = "unauthorized"

            returnResponse = flask.Response()
            returnResponse.headers["Content-Type"] = "application/json"
            returnResponse.status_code = 401  # Error code
            responseDict = {}
            responseDict["message"] = errorMessage
            returnResponse.set_data(json.dumps(responseDict))
            return returnResponse
Exemplo n.º 3
0
        def ThreadedFunction(from_email="",
                             username="",
                             title="",
                             agency="",
                             userEmail="",
                             link=""):
            """
            This inner function sends emails in a new thread as there could be lots of admins

            from_email -- (string) the from email address
            username -- (string) the name of the  user
            title  --   (string) the title of the  user
            agency -- (string) the agency of the  user
            userEmail -- (string) the email of the user
            link  -- (string) the broker email link
            """
            threadedDatabase = UserHandler()
            try:
                for user in threadedDatabase.getUsersByType("website_admin"):
                    emailTemplate = {
                        '[REG_NAME]': username,
                        '[REG_TITLE]': title,
                        '[REG_AGENCY]': agency,
                        '[REG_EMAIL]': userEmail,
                        '[URL]': link
                    }
                    newEmail = sesEmail(user.email,
                                        system_email,
                                        templateType="account_creation",
                                        parameters=emailTemplate,
                                        database=threadedDatabase)
                    newEmail.send()
            finally:
                InterfaceHolder.closeOne(threadedDatabase)
        def ThreadedFunction (from_email="",username="",title="",cgac_code="",userEmail="" ,link="") :
            """
            This inner function sends emails in a new thread as there could be lots of admins

            from_email -- (string) the from email address
            username -- (string) the name of the  user
            title  --   (string) the title of the  user
            agency -- (string) the agency of the  user
            userEmail -- (string) the email of the user
            link  -- (string) the broker email link
            """
            threadedDatabase =  UserHandler()
            try:
                agency_name = self.interfaces.validationDb.getAgencyName(cgac_code)
                agency_name = "Unknown" if agency_name is None else agency_name
                for user in threadedDatabase.getUsersByType("website_admin"):
                    emailTemplate = {'[REG_NAME]': username, '[REG_TITLE]':title, '[REG_AGENCY_NAME]':agency_name,
                                     '[REG_CGAC_CODE]': cgac_code,'[REG_EMAIL]' : userEmail,'[URL]':link}
                    newEmail = sesEmail(user.email, system_email,templateType="account_creation",parameters=emailTemplate,database=threadedDatabase)
                    newEmail.send()
                for user in threadedDatabase.getUsersByType("agency_admin"):
                    if user.cgac_code == cgac_code:
                        emailTemplate = {'[REG_NAME]': username, '[REG_TITLE]': title, '[REG_AGENCY_NAME]': agency_name,
                             '[REG_CGAC_CODE]': cgac_code,'[REG_EMAIL]': userEmail, '[URL]': link}
                        newEmail = sesEmail(user.email, system_email, templateType="account_creation", parameters=emailTemplate,
                                database=threadedDatabase)
                        newEmail.send()

            finally:
                InterfaceHolder.closeOne(threadedDatabase)
        def ThreadedFunction(from_email="",
                             username="",
                             title="",
                             cgac_code="",
                             userEmail="",
                             link=""):
            """
            This inner function sends emails in a new thread as there could be lots of admins

            from_email -- (string) the from email address
            username -- (string) the name of the  user
            title  --   (string) the title of the  user
            agency -- (string) the agency of the  user
            userEmail -- (string) the email of the user
            link  -- (string) the broker email link
            """
            threadedDatabase = UserHandler()
            try:
                agency_name = self.interfaces.validationDb.getAgencyName(
                    cgac_code)
                agency_name = "Unknown" if agency_name is None else agency_name
                for user in threadedDatabase.getUsersByType("website_admin"):
                    emailTemplate = {
                        '[REG_NAME]': username,
                        '[REG_TITLE]': title,
                        '[REG_AGENCY_NAME]': agency_name,
                        '[REG_CGAC_CODE]': cgac_code,
                        '[REG_EMAIL]': userEmail,
                        '[URL]': link
                    }
                    newEmail = sesEmail(user.email,
                                        system_email,
                                        templateType="account_creation",
                                        parameters=emailTemplate,
                                        database=threadedDatabase)
                    newEmail.send()
                for user in threadedDatabase.getUsersByType("agency_admin"):
                    if user.cgac_code == cgac_code:
                        emailTemplate = {
                            '[REG_NAME]': username,
                            '[REG_TITLE]': title,
                            '[REG_AGENCY_NAME]': agency_name,
                            '[REG_CGAC_CODE]': cgac_code,
                            '[REG_EMAIL]': userEmail,
                            '[URL]': link
                        }
                        newEmail = sesEmail(user.email,
                                            system_email,
                                            templateType="account_creation",
                                            parameters=emailTemplate,
                                            database=threadedDatabase)
                        newEmail.send()

            finally:
                InterfaceHolder.closeOne(threadedDatabase)
        def ThreadedFunction (from_email="",username="",title="",agency="",userEmail="" ,link="") :
            """
            This inner function sends emails in a new thread as there could be lots of admins

            from_email -- (string) the from email address
            username -- (string) the name of the  user
            title  --   (string) the title of the  user
            agency -- (string) the agency of the  user
            userEmail -- (string) the email of the user
            link  -- (string) the broker email link
            """
            threadedDatabase =  UserHandler()
            try:
                for user in threadedDatabase.getUsersByType("website_admin") :
                    emailTemplate = {'[REG_NAME]': username, '[REG_TITLE]':title, '[REG_AGENCY]':agency,'[REG_EMAIL]' : userEmail,'[URL]':link}
                    newEmail = sesEmail(user.email, system_email,templateType="account_creation",parameters=emailTemplate,database=threadedDatabase)
                    newEmail.send()
            finally:
                InterfaceHolder.closeOne(threadedDatabase)
Exemplo n.º 7
0
def setupEmails():
    """Create email templates from model metadata."""
    userDb = UserHandler()

    # insert email template types
    typeList = [('validate_email', ''), ('account_approved', ''),
                ('account_rejected', ''), ('reset_password', ''),
                ('account_creation', ''), ('account_creation_user', ''),
                ('unlock_account', '')]
    for t in typeList:
        emailId = userDb.session.query(
            EmailTemplateType.email_template_type_id).filter(
                EmailTemplateType.name == t[0]).one_or_none()
        if not emailId:
            type = EmailTemplateType(name=t[0], description=t[1])
            userDb.session.add(type)

    # insert email templates

    #Confirm
    template = "This email address was just used to create a user account with the DATA Act Broker.  To continue the registration process, please click <a href='[URL]'>here</a>. The link will expire in 24 hours. <br />  <br />  If you did not initiate this process, you may disregard this email.<br /><br />The DATA Act Broker Helpdesk<br />[email protected] "
    userDb.loadEmailTemplate("DATA Act Broker - Registration", template,
                             "validate_email")

    #Approve
    template = "Thank you for registering for a user account with the DATA Act Broker. Your request has been approved by the DATA Act Broker Help Desk. You may now log into the Data Broker portal, using the password you created at registration, by clicking <a href='[URL]'>here</a>.<br /><br /> If you have any questions, please contact the DATA Act Broker Help Desk at [EMAIL].<br /><br />DATA Act Broker Helpdesk<br />[email protected]"
    userDb.loadEmailTemplate("DATA Act Broker - Access Approved", template,
                             "account_approved")

    #Reject
    template = "Thank you for requesting log-in credentials for the DATA Act Broker. Your attempt to register has been denied. If you believe this determination was made in error, please contact the DATA Act Broker Helpdesk at [email protected].<br /><br />DATA Act Broker Helpdesk<br />[email protected]"
    userDb.loadEmailTemplate("DATA Act Broker - Access Denied", template,
                             "account_rejected")

    #Password Reset
    template = "You have requested your password to be reset for your account. Please click the following link <a href='[URL]'>here</a> to start the processs. The link will expire in 24 hours. <br/> <br/> If you did not request this password reset, please notify the DATA Act Broker Helpdesk ([email protected]) <br /><br />DATA Act Broker Helpdesk<br /><br />[email protected]"
    userDb.loadEmailTemplate("DATA Act Broker - Password Reset", template,
                             "reset_password")

    #Admin Email
    template = "This email is to notify you that the following person has requested an account for the DATA Act Broker:<br /><br />Name: [REG_NAME]<br /><br />Title:  [REG_TITLE]<br /><br />Agency Name:  [REG_AGENCY_NAME]<br /><br />CGAC Code: [REG_CGAC_CODE]<br /><br />Email: [REG_EMAIL]<br /><br /><br /><br />To approve or deny this user for access to the Data Broker, please click <a href='[URL]'>here</a>.<br /><br />This action must be taken within 24 hours. <br /><br />Thank you for your prompt attention.<br /><br />DATA Act Broker Helpdesk<br />[email protected]"
    userDb.loadEmailTemplate("New Data Broker registration - Action Required",
                             template, "account_creation")

    #User Email When finished submitting
    template = (
        "Thank you for registering a DATA Act Broker user account. "
        "The final registration step is for the Help Desk to review your "
        "request. You should receive an e-mail update from them within one "
        "business day, saying whether they've approved or denied your access."
        "<br /><br />"
        "Until the Help Desk approves your request, you won't be able to log "
        "into the Broker. Thanks for being patient with the security process--"
        "we appreciate your interest and look forward to working with you."
        "<br /><br/>"
        "If you have any questions or haven't received a follow-up e-mail "
        "within one business day, please get in touch with the Help Desk at "
        "[EMAIL]."
        "<br /><br />"
        "The DATA Act Implementation Team <br />"
        "[EMAIL]")
    userDb.loadEmailTemplate("DATA Act Broker - Registration", template,
                             "account_creation_user")

    #Unlock account email
    template = "Your account has been unlocked and requires your password to be reset. Please click the following link <a href='[URL]'>here</a> to start the processs. The link will expire in 24 hours. <br/> <br/> If you did not request your account to be unlocked, please notify the DATA Act Broker Helpdesk ([email protected]) <br /><br />DATA Act Broker Helpdesk<br /><br />[email protected]"
    userDb.loadEmailTemplate("DATA Act Broker - Password Reset", template,
                             "unlock_account")

    InterfaceHolder.closeOne(userDb)
def setupEmails():
    """Create email templates from model metadata."""
    userDb = UserHandler()

    # insert email template types
    typeList = [
        ('validate_email', ''),
        ('account_approved', ''),
        ('account_rejected', ''),
        ('reset_password', ''),
        ('account_creation', ''),
        ('account_creation_user', '')
    ]
    for t in typeList:
        emailId = userDb.session.query(
            EmailTemplateType.email_template_type_id).filter(
            EmailTemplateType.name == t[0]).one_or_none()
        if not emailId:
            type = EmailTemplateType(name=t[0], description=t[1])
            userDb.session.add(type)

    # insert email templates

    #Confirm
    template = "This email address was just used to create a user account with the DATA Act Broker.  To continue the registration process, please click <a href='[URL]'>here</a>. The link will expire in 24 hours. <br />  <br />  If you did not initiate this process, you may disregard this email.<br /><br />The DATA Act Broker Helpdesk<br />[email protected] "
    userDb.loadEmailTemplate("DATA Act Broker - Registration", template, "validate_email")

    #Approve
    template = "Thank you for registering for a user account with the DATA Act Broker. Your request has been approved by the DATA Act Broker Help Desk. You may now log into the Data Broker portal, using the password you created at registration, by clicking <a href='[URL]'>here</a>.<br /><br /> If you have any questions, please contact the DATA Act Broker Help Desk at [EMAIL].<br /><br />DATA Act Broker Helpdesk<br />[email protected]"
    userDb.loadEmailTemplate("DATA Act Broker - Access Approved", template, "account_approved")

    #Reject
    template = "Thank you for requesting log-in credentials for the DATA Act Broker. Your attempt to register has been denied. If you believe this determination was made in error, please contact the DATA Act Broker Helpdesk at [email protected].<br /><br />DATA Act Broker Helpdesk<br />[email protected]"
    userDb.loadEmailTemplate("DATA Act Broker - Access Denied", template, "account_rejected")

    #Password Reset
    template = "You have requested your password to be reset for your account. Please click the following link <a href='[URL]'>here</a> to start the processs. The link will expire in 24 hours. <br/> <br/> If you did not request this password reset, please notify the DATA Act Broker Helpdesk ([email protected]) <br /><br />DATA Act Broker Helpdesk<br /><br />[email protected]"
    userDb.loadEmailTemplate("DATA Act Broker - Password Reset", template, "reset_password")

    #Admin Email
    template = "This email is to notify you that the following person has requested an account for the DATA Act Broker:<br /><br />Name: [REG_NAME]<br /><br />Title:  [REG_TITLE]<br /><br />Agency:  [REG_AGENCY]<br /><br />Email: [REG_EMAIL]<br /><br /><br /><br />To approve or deny this user for access to the Data Broker, please click <a href='[URL]'>here</a>.<br /><br />This action must be taken within 24 hours. <br /><br />Thank you for your prompt attention.<br /><br />DATA Act Broker Helpdesk<br />[email protected]"
    userDb.loadEmailTemplate("New Data Broker registration - Action Required", template, "account_creation")

    #User Email When finished submitting
    template = ("Thank you for registering a DATA Act Broker user account. "
        "The final registration step is for the Help Desk to review your "
        "request. You should receive an e-mail update from them within one "
        "business day, saying whether they've approved or denied your access."
        "<br /><br />"
        "Until the Help Desk approves your request, you won't be able to log "
        "into the Broker. Thanks for being patient with the security process--"
        "we appreciate your interest and look forward to working with you."
        "<br /><br/>"
        "If you have any questions or haven't received a follow-up e-mail "
        "within one business day, please get in touch with the Help Desk at "
        "[EMAIL]."
        "<br /><br />"
        "The DATA Act Implementation Team <br />"
        "[EMAIL]")
    userDb.loadEmailTemplate("DATA Act Broker - Registration", template, "account_creation_user")

    InterfaceHolder.closeOne(userDb)