Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin Authentication Refactor #5

Merged
merged 16 commits into from
Jan 11, 2018
Merged

Conversation

Reltre
Copy link

@Reltre Reltre commented Dec 4, 2017

This PR adds the following:

  1. Authentication logic for admins
  2. Views related to log in for admins
  3. Database schema for users, with required attributes, including admin role.
  4. Testing for related models and controllers, as well as a spec for the log in feature.
  5. A small amount of jQuery has been added to enable error messaging.

This PR so far only cover authentication of existing users. To run a sanity test on this, be sure to have an existing user, preferably one with admin role, in the database.

Some filters should probably be added in the future to enforce the presence of a logged in user when accessing different parts of the site. This was left out to avoid potential merge conflicts with other branches.

@Reltre Reltre requested a review from seport December 4, 2017 02:33
Copy link
Owner

@seport seport left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looking awesome! A few requests:

  1. Can you add an admin user with username admin and password password to the setup script for testing purposes?
  2. It would also be nice if you could rebase onto the rails branch and remove unnecessary files like some of the helpers and email things and other random things that don't really contribute to the ticket. (Just to really cross our t's and dot our i's)

Thanks so much! Other than these small changes it looks really good to me so far. :)

@@ -0,0 +1,4 @@
module ApplicationCable
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain channels and application cables?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or remove this if it was just something rails generated at some point.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this. ApplicationCable seems good for implementing features for currently logged users, in particular, for tracking things in real time. Not sure this is something we need at the moment. Might be a nice to have for later on though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then again, YAGNI; I'll remove it for the time being.

@@ -0,0 +1,2 @@
module ApplicationHelper
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these helpers helping anything? Will they in the future, or should we delete these?

@@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this job doing anything?

@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we need the mailer for?

@@ -0,0 +1,7 @@
class User < ApplicationRecord
validates :email, presence: true
validates :password, presence: true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are we encrypting the password?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once has_secure_password was added below, passwords are encrypted with the bcrypt gem when a User model is saved.

bin/setup Outdated
@@ -0,0 +1,38 @@
#!/usr/bin/env ruby
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a setup step that creates an admin user? This can also be a separate ticket though.

config/cable.yml Outdated
@@ -0,0 +1,10 @@
development:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a websockets thing? We might not need Cable either.

@@ -0,0 +1,33 @@
# Files in the config/locales directory are used for internationalization
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually we should do something like this, but I don't think we need it in this iteration of the app, and there are a couple of new ways I've been learning about doing this other than a yml file which seem pretty interesting.... we can put it in the icebox and discuss it later.

config/routes.rb Outdated
Rails.application.routes.draw do
root 'welcome#index'

namespace :admin do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also add a route for /admin which is either the admin index (can just be a hello world page for now) if there is an admin session logged in, or redirects to admin/login otherwise?

Copy link
Author

@Reltre Reltre Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added in a before filter for this and an index action for an admin session, well the index page works as a placeholder I guess? I think until we have a dedicated admin view, that we should just have admins navigate to the welcome page on log in.

@@ -0,0 +1,19 @@
require "rails_helper"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay testing!! bitmoji

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yayy!

@seport
Copy link
Owner

seport commented Dec 21, 2017

I have a few more comments actually,

  1. please set the password field in the view to be a password field rather than a text field
  2. After login the admin should be redirected to an admin dashboard at /admin. For now it can just be a simple hello world page for proof of concept.
  3. I'm not totally sure the session stuff is working. When I go back to /admin/login after logging in (and being redirected to the homepage) I should be redirected immediately, because I am already logged in.

@Reltre Reltre changed the base branch from master to rails January 2, 2018 20:01
@Reltre
Copy link
Author

Reltre commented Jan 2, 2018

@seport I've made the changes you've request above. One thing we'll need eventually is a way to log out. At the moment, we have to hop into the inspector and delete the session cookie directly to log out.

There's an admin user setup in our seeds file now. I've also added some filters related to login. Also, I realized that this branch was set to merge into master. Once I set it to merge into the "rails" branch, most of those unrelated files went away 😃

Copy link
Owner

@seport seport left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@seport seport merged commit aacf0a7 into rails Jan 11, 2018
@seport seport deleted the chores/admin-authentication-refactor branch January 18, 2018 03:54
@seport seport added this to the v1.0.0 milestone Mar 20, 2018
@seport seport added the v1.0.0 label Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants