Code Monkey home page Code Monkey logo

loginkit's Introduction

LoginKit

Version License Platform Made with Love by Icalia Labs

About

LoginKit is a quick and easy way to add Facebook and email Login/Signup UI to your app. If you need to quickly prototype an app, create an MVP or finish an app for a hackathon, LoginKit can help you by letting you focus on what makes your app special and leave login/signup to LoginKit. But if what you really want is a really specific and customized login/singup flow you are probably better off creating it on your own.

LoginKit handles Signup & Login, via Facebook & Email. It takes care of the UI, the forms, validation, and Facebook SDK access. All you need to do is start LoginKit, and then make the necessary calls to your own backend API to login or signup.

This is a simple example of how your login can look. Check out the example project to see how this was done and tinker around with it.

This other example is LoginKit in use in one of our client apps.

What's New

v.1.0.0

  • Ability to use LoginViewController, SignupViewController and PasswordViewController on it's own without having to use the LoginCoordinator
  • Ability to hide Login, Signup and Facebook buttons in initial screen
  • Added ability to remove background gradient
  • Added ability to remove animation when starting the Login Coordinator
  • Fixed an issue with the keyboard mover not working in some cases
  • Fixes/Improvements to the sample project
  • Updated Facebook SDK to latest version

Requirements

Installation

LoginKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "ILLoginKit"

Getting Started

Login Coordinator

Everything is handled through the LoginCoordinator class. You instantiate it and pass the root view controller which is the UIViewController from which the LoginKit process will be started (presented) on. This will usually be self.

import LoginKit

class ViewController: UIViewController { 

    lazy var loginCoordinator: LoginCoordinator = {
        return LoginCoordinator(rootViewController: self)
    }()
    
    ...

    func showLogin() {
        loginCoordinator.start()
    }
    
    ...

}

Afterwards call start on the coordinator. That's it!

Customization

Of course you will want to customize the Login Coordinator to be able to supply your own UI personalization, and to perform the necessary actions on login or signup.

That is done by subclassing the LoginCoordinator class.

class LoginCoordinator: ILLoginKit.LoginCoordinator {

}

Start

Handle anything you want to happen when LoginKit starts. Make sure to call super.

override func start(animated: Bool = true) {
    super.start(animated: animated)
    configureAppearance()
}

Configuration

You can set any of these properties on the configuration property of the superclass to change the way LoginKit looks. Besides the images, all other properties have defaults, no need to set them if you don't need them.

Property Effect
backgroundImage The background image that will be used in all ViewController's.
backgroundImageGradient Set to false to remove the gradient from the background image. (Default is true)
mainLogoImage A logo image that will be used in the initial ViewController.
secondaryLogoImage A smaller logo image that will be used on all ViewController's except the initial one.
tintColor The tint color for the button text and background color.
errorTintColor The tint color for error texts.
loginButtonText The text for the login button.
signupButtonText The text for the signup button.
facebookButtonText The text for the facebook button.
forgotPasswordButtonText The text for the forgot password button.
recoverPasswordButtonText The text for the recover password button.
namePlaceholder The placeholder that will be used in the name text field.
emailPlaceholder The placeholder that will be used in the email text field.
passwordPlaceholder The placeholder that will be used in the password text field.
repeatPasswordPlaceholder The placeholder that will be used in the repeat password text field.
shouldShowSignupButton To hide the signup button set to false. (Default is true)
shouldShowLoginButton To hide the login button set to false. (Default is true)
shouldShowFacebookButton To hide the Facebook button set to false. (Default is true)
shouldShowForgotPassword To hide the forgot password button set to false. (Default is true)
// Customize LoginKit. All properties have defaults, only set the ones you want.
func configureAppearance() {
    // Customize the look with background & logo images
    configuration.backgroundImage = 
    configuration.mainLogoImage =
    configuration.secondaryLogoImage =

    // Change colors
    configuration.tintColor = UIColor(red: 52.0/255.0, green: 152.0/255.0, blue: 219.0/255.0, alpha: 1)
    configuration.errorTintColor = UIColor(red: 253.0/255.0, green: 227.0/255.0, blue: 167.0/255.0, alpha: 1)

    // Change placeholder & button texts, useful for different marketing style or language.
    configuration.loginButtonText = "Sign In"
    configuration.signupButtonText = "Create Account"
    configuration.facebookButtonText = "Login with Facebook"
    configuration.forgotPasswordButtonText = "Forgot password?"
    configuration.recoverPasswordButtonText = "Recover"
    configuration.namePlaceholder = "Name"
    configuration.emailPlaceholder = "E-Mail"
    configuration.passwordPlaceholder = "Password!"
    configuration.repeatPasswordPlaceholder = "Confirm password!"
}

You can also create your own type that conforms to the ConfigurationSource protocol, or use the DefaultConfiguration struct. Then just set it on the configuration object like so.

configuration = DefaultConfiguration(backgroundImage: signupButtonText: "Create Account",
					 loginButtonText: "Sign In",
					 facebookButtonText: "Login with Facebook",
					 forgotPasswordButtonText: "Forgot password?",
					 recoverPasswordButtonText: "Recover",
					 emailPlaceholder: "E-Mail",
					 passwordPlaceholder: "Password!",
					 repeatPasswordPlaceholder: "Confirm password!",
					 namePlaceholder: "Name",
					 shouldShowSignupButton: false,
					 shouldShowLoginButton: true,
					 shouldShowFacebookButton: false,
					 shouldShowForgotPassword: true)x

Completion Callbacks

Override these other 4 callback methods to handle what happens after the user tries to login, signup, recover password or enter with facebook.

Here you would call your own API.

// Handle login via your API
override func login(email: String, password: String) {
    print("Login with: email =\(email) password = \(password)")
}

// Handle signup via your API
override func signup(name: String, email: String, password: String) {
    print("Signup with: name = \(name) email =\(email) password = \(password)")
}

// Handle Facebook login/signup via your API
override func enterWithFacebook(profile: FacebookProfile) {
    print("Login/Signup via Facebook with: FB profile =\(profile)")
}

// Handle password recovery via your API
override func recoverPassword(email: String) {
    print("Recover password with: email =\(email)")
}

Finish

After successfull login call the finish() method on LoginCoordinator. Be sure to call super.

override func finish(animated: Bool = true) {
    super.finish(animated: animated)
}

Code

The final result would look something like this.

import Foundation
import ILLoginKit

class LoginCoordinator: ILLoginKit.LoginCoordinator {

    // MARK: - LoginCoordinator

    override func start(animated: Bool = true) {
        super.start(animated: animated)
        configureAppearance()
    }

    override func finish(animated: Bool = true) {
        super.finish(animated: animated)
    }

    // MARK: - Setup

    // Customize LoginKit. All properties have defaults, only set the ones you want.
    func configureAppearance() {
        // Customize the look with background & logo images
        configuration.backgroundImage = #imageLiteral(resourceName: "Background")
        // mainLogoImage =
        // secondaryLogoImage =

        // Change colors
        configuration.tintColor = UIColor(red: 52.0/255.0, green: 152.0/255.0, blue: 219.0/255.0, alpha: 1)
        configuration.errorTintColor = UIColor(red: 253.0/255.0, green: 227.0/255.0, blue: 167.0/255.0, alpha: 1)

        // Change placeholder & button texts, useful for different marketing style or language.
        configuration.loginButtonText = "Sign In"
        configuration.signupButtonText = "Create Account"
        configuration.facebookButtonText = "Login with Facebook"
        configuration.forgotPasswordButtonText = "Forgot password?"
        configuration.recoverPasswordButtonText = "Recover"
        configuration.namePlaceholder = "Name"
        configuration.emailPlaceholder = "E-Mail"
        configuration.passwordPlaceholder = "Password!"
        configuration.repeatPasswordPlaceholder = "Confirm password!"
    }

    // MARK: - Completion Callbacks

    // Handle login via your API
    override func login(email: String, password: String) {
        print("Login with: email =\(email) password = \(password)")
    }
    
    // Handle signup via your API
    override func signup(name: String, email: String, password: String) {
        print("Signup with: name = \(name) email =\(email) password = \(password)")
    }

    // Handle Facebook login/signup via your API
    override func enterWithFacebook(profile: FacebookProfile) {
        print("Login/Signup via Facebook with: FB profile =\(profile)")
    }

    // Handle password recovery via your API
    override func recoverPassword(email: String) {
        print("Recover password with: email =\(email)")
    }

}

Using the ViewController's without the LoginCoordinator

If you only need to use the LoginViewController or SignupViewController or PasswordViewController on it's own, without using the LoginCoordinator, now you can.

Just subclass any of them, and set configuration property in the viewDidLoad() method before calling super.viewDidLoad().

class OverridenLoginViewController: LoginViewController {

    override func viewDidLoad() {
	configuration = Settings.defaultLoginConfig // configure before calling super
	super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

}

Then just present the ViewController, and set the delegate property to receive the appropiate callbacks for that controller.

Author

Daniel Lozano, [email protected]

License

LoginKit is available under the MIT license. See the LICENSE file for more info.

loginkit's People

Contributors

danlozano avatar kurenn avatar quynhnguyen avatar rafiki270 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

loginkit's Issues

Perfect Image Size for Logo?

Hi, I want to use a logo in LoginKit, however they are not placed correctly. I figure this is cz the logo is too big. What size logo would return the perfect positioning?

Validator Pod Errors

I am getting errors from the Validator pod which have been since resolved in the original project. Is it possible to update the Validator pod used in this framework to the latest? Thanks.

Error Builing App

hi after i install LoginKit from cocoapod

if i try the run the app i have this error in build phase

"FBSDKLoginKit" Incopatible block pointer types 'void(^)(BOOL) to parameter tof type 'void.....
line 505 FBSDKLoginManager.m

same error line 549 and 551

Can't override default configuration

I can't seem to override the default configurations. My code is set up just like it was before version 1.0 except for the updates needed for version 1.0.

i.e changing backgroundImage to configuration.backgroundImage

It seems as though it's initializing with the defaults before it hits my own in ConfigureAppearance()

De-Init loginCoordinator not happening &

Hello,

Thanks for the repo, great help, but I’ve spent over 12 hours in past 2 days trying to make it work but it won’t.
.
I’m using fire base function where authentication state change, when successful log in, triggers function in appdelegate to perform .finish() and change root view controllers.
.
But looking at view heirachy, and tracking initial controller & coordinator, the last two never get de-unit. And the initial view controller remains as controller and just its view in the system.
.
Also lastly when I’m trying to change rootviewcontroller from let to var, in coordinator class, since maybe that is causing retain cycle, it throws runtime error, and overall not letting me edit pod file without errors.
.
Appreciated if you do respond. Been blowing my brain with this for past two days.

Custom field validations

Is it possible to change the validation rules used on the different text fields? For example, I want to use the Name field as a Username field, however it currently requires a space between two words

How to get out of loop Coordinator calling start()

I'm unclear about when I am supposed to be calling .finish(). The logInCoordinator.start() call is in the viewWillAppear of my app's rootViewController like the example shows and after successful LogIn and calling Finish it just goes right back to presenting another LogIn screen. Can someone please help, what am I missing?

Wrong Installation Command

In the READ.ME, "Installation" Part,
the correct command should be pod "LoginKit" rather than pod "ILLoginKit"

Three classes not conforming to protocol ValidatableInterfaceElement

Hi,

I've tried using your LoginKit but apparently after adding it using cocoapods I'm getting the following errors:

Type 'UISlider' does not conform to protocol 'ValidatableInterfaceElement' (UISlider+Validator.swift)
Type 'UITextField' does not conform to protocol 'ValidatableInterfaceElement' (UITextField+Validator.swift)
Type 'UITextView' does not conform to protocol 'ValidatableInterfaceElement' (UITextView+Validator.swift)

All these appear inside Validator pod, which I think is a dependency pod for your LoginKit.

Please advise which should I do to get rid fo the errors.

Thank you,
Bogdan H.

Keyboard mover doesn't work

@danlozano Hello, thanks for making this repository its great. Theres just one problem. The keyboard mover doesn't move when you switch textfields. Like lets say you go and create an account and click the fist textfield and click next and next, the view doesn't move above the keyboard and the textfield is stuck beneath the keyboard. The same is for login. You click on username and the contine button is stuck beneath the keyboard. Could you fix this in a new update so that all three views(password, signup, and login work for all screen sizes when the keyboard is up). Thanks.

No such module 'LoginKit'

In my Podfile I added pod "ILLoginKit", then I installed pod as a normal installation. After that I went into Xcode and add import LoginKit but for some reason its yelling: No such module 'LoginKit'. Anyone encounter this problem or know how to fix it?

I'm on Xcode Version 10.1 (10B61)

Hide Facebook Login button?

I've set shouldShowFacebookButton to false, but the button still appears. Is the Facebook sign in button required?

Cancel Button?

Probably a stupid question - but is there a way to show a cancel button?

For example, if my user clicks on my 'accounts' tab to either select login, or signup from the UI generated from the loginCoordinator.start() command. But actually changes his/her mind...is there a cancel button to dismiss said view that is generated?

Undeclared Type 'LoginViewController'

I am getting an error of 'undeclared type' with the LoginViewController class, this does not happen with LoginCoordinator class and the only difference I can see is that the LoginCoordinator class statement has an 'open' prefix to set the access level.

more customization and support for ios11

hmmm like you can choose whether facebook login is enabled, and rules to validate the username/password?

and there has been a change in api of CGFont
public /not inherited/ init?(_ provider: CGDataProvider)
returns an optional in ios11 sdk now

Hor remove gradient

hi i want a simple image as background
how can i remove the white gradient?

error in textfields

The text fields are returning empty string in all views:
Signup with: name = email = password =
Login with: email = password =

Blank page with only FB button

When it gets presented... it only comes with the facebook button... this is with the exact sample code provided in the example project.
simulator screen shot apr 21 2017 10 46 46 am

Ios 11 closing view cause crash

hi, closing all view
make the app crash

the view are nulled on close and if i try to open again the view it crash (nulled view)

i need to comment all
navigationController = nil
initialViewController = nil
loginViewController = nil
signupViewController = nil
passwordViewController = nil

LoginCoordinator can't performSegue

Hi,

Thanks for your repo.

I need to performSegue(withIdentifier: when user login.

I added this code:

override func login(email: String, password: String) {
        // Handle login via your API
        print("Login with: email =\(email) password = \(password)")
        
        dataManager.login(email: email, password: "123456") { (response, error) in
            if let error = error {
                print(error)
            } else if let response = response {
                print("response \(response.count)")
                DispatchQueue.main.async {
                    self.performSegue(withIdentifier: "toMainVC", sender: nil)
                }
            }
        }
    }

I got this error:

Value of type 'LoginCoordinator' has no member 'performSegue'

Could you please guide me how to solve it?

Thanks.

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.