Created
February 5, 2013 18:38
-
-
Save brianknapp/4716581 to your computer and use it in GitHub Desktop.
This is a overly simplistic sign in user action that demonstrates roughly how a sign in might work in Obvious with users and user sessions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require_relative '../entities/user' | |
| require_relative '../entities/user_session' | |
| class SignInUser | |
| def initialize user_jack, user_session_jack | |
| @user_jack = user_jack | |
| @user_session_jack = user_session_jack | |
| end | |
| def execute input | |
| unless input.has_shape? email: String, password: String | |
| raise ArgumentError.new 'invalid input format' | |
| end | |
| # find the user and check credentials | |
| # use: UserJack.get, User.populate | |
| user_data = @user_jack.find email: input[:email] | |
| user = User.new | |
| user.populate user_data | |
| # set default id and values for new UserSession entity | |
| session_data = { | |
| id: -1, | |
| email: user_data[:email], | |
| token: generate_token | |
| } | |
| # create/populate UserSession object | |
| # use: UserSession.populate | |
| session = UserSession.new | |
| session.populate session_data | |
| # save session to jack | |
| # use: UserSessionJack.save, UserSession.to_hash | |
| # return the result | |
| @user_session_jack.save session.to_hash | |
| end | |
| def generate_token | |
| 'random token!' | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment