Giter Site home page Giter Site logo

swiftswot's Introduction

SwiftSWOT

Platforms Swift 5.3 Vapor 4

SwiftSWOT is a Vapor service for verifying academic emails against the SWOT database.

SWOT is a community-driven database that has a large list of valid academic emails. This is useful for things like providing student discounts. This package checks against that database to give a reasonably good idea of if a given email is an academic email.

Installation

Installation is done through the Swift Package Manager

.package(url: "https://github.com/thecoolwinter/SwiftSWOT.git", from: "1.0.1")

.target(name: "App", dependencies: [
    .product(name: "Vapor", package: "vapor"),
    .product(name: "SwiftSWOT", package: "SwiftSWOT")
])

Usage

Validate Academic Emails

In your request path, validate emails using the SWOT variable on the request.

app.on(.GET, "validateStudent", ":email") { (req) -> [String: String] in
    guard let email = try? req.parameters.require("email") else {
        return [
            "valid": "false",
            "reason": "Please provide an email to validate."
        ]
    }
    
    let isValidEmail = req.SWOT.validateEmail(email)
    if isValidEmail {
        return [
            "valid": "true"
        ]
    } else {
        return [
            "valid": "false",
            "reason": "Not a valid academic email address."
        ]
    }
}

You can also get the academic institution's name from the email.

app.on(.GET, "institution", ":email") { (req) -> [String: String] in
    guard let email = try? req.parameters.require("email") else {
        return [
            "valid": "false",
            "reason": "Please provide an email to validate.",
            "institutionName": ""
        ]
    }
    
    let institutionName = req.SWOT.institutionFromEmail(email)
    if institutionName != nil {
        return [
            "valid": "true",
            "institutionName": institutionName!
        ]
    } else {
        return [
            "valid": "false",
            "reason": "Not a valid academic email address.",
            "institutionName": ""
        ]
    }
}

Configuration & Customization

The configuration can be set using the SwiftSWOTConfig object on your app.

You can configure:

  • Blacklist
  • Custom institutions that might not be in the database
  • Toggle logging
app.SWOT.configuration = .init(loggingEnabled: true, // Default `false`
                                blacklist: [ // Array of domain names to ignore
                                	"gmail.com",
                                  "yahoo.org"
                                ],
                                trustedDomains: [
                                	"my.gcu.edu": "Grand Canyon University"
                                ])

trustedDomains is a dictionary of Domain : Institution Name. The domain is what SWOT wil search for when validating an email, Institution Name is what will be returned from req.SWOT.institutionFromEmail(email)

Note: gmail.com and yahoo.org are there for example, they will return false if checked against the database.

swiftswot's People

Contributors

thecoolwinter avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.