forked from External/greenlight
Added field to track users last login (#2367)
This commit is contained in:
parent
7a2405aa9e
commit
14350c5f5d
|
@ -24,6 +24,7 @@ module Authenticator
|
|||
migrate_twitter_user(user)
|
||||
|
||||
session[:user_id] = user.id
|
||||
user.update(last_login: Time.zone.now)
|
||||
|
||||
logger.info("Support: #{user.email} has successfully logged in.")
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddLastLoginToUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :users, :last_login, :datetime
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2020_06_15_190507) do
|
||||
ActiveRecord::Schema.define(version: 2020_12_14_232153) do
|
||||
|
||||
create_table "active_storage_attachments", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
|
@ -142,6 +142,7 @@ ActiveRecord::Schema.define(version: 2020_06_15_190507) do
|
|||
t.datetime "activated_at"
|
||||
t.boolean "deleted", default: false, null: false
|
||||
t.integer "role_id"
|
||||
t.datetime "last_login"
|
||||
t.index ["created_at"], name: "index_users_on_created_at"
|
||||
t.index ["deleted"], name: "index_users_on_deleted"
|
||||
t.index ["email"], name: "index_users_on_email"
|
||||
|
|
|
@ -272,6 +272,19 @@ describe SessionsController, type: :controller do
|
|||
}
|
||||
}.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
|
||||
it "correctly sets the last_login field after the user is created" do
|
||||
post :create, params: {
|
||||
session: {
|
||||
email: @user1.email,
|
||||
password: 'example',
|
||||
},
|
||||
}
|
||||
|
||||
@user1.reload
|
||||
|
||||
expect(@user1.last_login).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET/POST #omniauth" do
|
||||
|
@ -372,6 +385,15 @@ describe SessionsController, type: :controller do
|
|||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
|
||||
it "correctly sets the last_login field after the user is created" do
|
||||
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:google]
|
||||
get :omniauth, params: { provider: :google }
|
||||
|
||||
u = User.last
|
||||
|
||||
expect(u.last_login).to_not be_nil
|
||||
end
|
||||
|
||||
context 'twitter deprecation' do
|
||||
it "should not allow new user sign up with omniauth twitter" do
|
||||
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:twitter]
|
||||
|
|
|
@ -139,6 +139,15 @@ describe UsersController, type: :controller do
|
|||
expect(flash[:success]).to be_present
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
|
||||
it "correctly sets the last_login field after the user is created" do
|
||||
params = random_valid_user_params
|
||||
post :create, params: params
|
||||
|
||||
u = User.find_by(name: params[:user][:name], email: params[:user][:email])
|
||||
|
||||
expect(u.last_login).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "disallow greenlight accounts" do
|
||||
|
|
Loading…
Reference in New Issue