parent
fa92abf1ee
commit
123df86804
@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the Tokens controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the UserActions controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module LoginHelper
|
||||
extend ActiveSupport::Concern
|
||||
def edu_setting(name)
|
||||
EduSetting.get(name)
|
||||
end
|
||||
def autologin_cookie_name
|
||||
edu_setting('autologin_cookie_name').presence || 'autologin'
|
||||
end
|
||||
def set_token_session(user)
|
||||
Token.create(:value => (session.id.to_s || session[:session_id]),:user => user, :action => User::SESSION_ACTION, :ip => request.remote_ip, :browser => (request&.headers["User-Agent"] || ''))
|
||||
end
|
||||
|
||||
def set_autologin_cookie(user)
|
||||
token = Token.get_or_create_permanent_login_token(user, "autologin")
|
||||
cookie_options = {
|
||||
:value => token.value,
|
||||
:expires => 1.month.from_now,
|
||||
:path => '/',
|
||||
:secure => false,
|
||||
:httponly => false
|
||||
}
|
||||
if edu_setting('cookie_domain').present?
|
||||
cookie_options = cookie_options.merge(domain: edu_setting('cookie_domain'))
|
||||
end
|
||||
cookies[autologin_cookie_name] = cookie_options
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,70 @@
|
||||
class TokensController < ApplicationController
|
||||
before_action :set_token, only: %i[ show edit update destroy ]
|
||||
|
||||
# GET /tokens or /tokens.json
|
||||
def index
|
||||
@tokens = Token.all
|
||||
end
|
||||
|
||||
# GET /tokens/1 or /tokens/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /tokens/new
|
||||
def new
|
||||
@token = Token.new
|
||||
end
|
||||
|
||||
# GET /tokens/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /tokens or /tokens.json
|
||||
def create
|
||||
@token = Token.new(token_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @token.save
|
||||
format.html { redirect_to token_url(@token), notice: "Token was successfully created." }
|
||||
format.json { render :show, status: :created, location: @token }
|
||||
else
|
||||
format.html { render :new, status: :unprocessable_entity }
|
||||
format.json { render json: @token.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /tokens/1 or /tokens/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @token.update(token_params)
|
||||
format.html { redirect_to token_url(@token), notice: "Token was successfully updated." }
|
||||
format.json { render :show, status: :ok, location: @token }
|
||||
else
|
||||
format.html { render :edit, status: :unprocessable_entity }
|
||||
format.json { render json: @token.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /tokens/1 or /tokens/1.json
|
||||
def destroy
|
||||
@token.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to tokens_url, notice: "Token was successfully destroyed." }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_token
|
||||
@token = Token.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def token_params
|
||||
params.require(:token).permit(:user_id, :action, :status, :value, :ip, :browser, :created_on)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,70 @@
|
||||
class UserActionsController < ApplicationController
|
||||
before_action :set_user_action, only: %i[ show edit update destroy ]
|
||||
|
||||
# GET /user_actions or /user_actions.json
|
||||
def index
|
||||
@user_actions = UserAction.all
|
||||
end
|
||||
|
||||
# GET /user_actions/1 or /user_actions/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /user_actions/new
|
||||
def new
|
||||
@user_action = UserAction.new
|
||||
end
|
||||
|
||||
# GET /user_actions/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /user_actions or /user_actions.json
|
||||
def create
|
||||
@user_action = UserAction.new(user_action_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @user_action.save
|
||||
format.html { redirect_to user_action_url(@user_action), notice: "User action was successfully created." }
|
||||
format.json { render :show, status: :created, location: @user_action }
|
||||
else
|
||||
format.html { render :new, status: :unprocessable_entity }
|
||||
format.json { render json: @user_action.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /user_actions/1 or /user_actions/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @user_action.update(user_action_params)
|
||||
format.html { redirect_to user_action_url(@user_action), notice: "User action was successfully updated." }
|
||||
format.json { render :show, status: :ok, location: @user_action }
|
||||
else
|
||||
format.html { render :edit, status: :unprocessable_entity }
|
||||
format.json { render json: @user_action.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /user_actions/1 or /user_actions/1.json
|
||||
def destroy
|
||||
@user_action.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to user_actions_url, notice: "User action was successfully destroyed." }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_user_action
|
||||
@user_action = UserAction.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def user_action_params
|
||||
params.require(:user_action).permit(:user_id, :action_type, :action_id, :ip)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,2 @@
|
||||
module TokensHelper
|
||||
end
|
||||
@ -0,0 +1,2 @@
|
||||
module UserActionsHelper
|
||||
end
|
||||
@ -0,0 +1,124 @@
|
||||
|
||||
class Token < ActiveRecord::Base
|
||||
include ApplicationHelper
|
||||
belongs_to :user
|
||||
validates_uniqueness_of :value
|
||||
|
||||
before_create :delete_previous_tokens, :generate_new_token
|
||||
|
||||
@@validity_time = 1.day
|
||||
STATUS_LOGIN = 0
|
||||
STATUS_LOGOUT = 1
|
||||
STATUS_EX_LOGIN = 2
|
||||
STATUS_EX_LOGOUT = 3
|
||||
STATUS_SELF_LOGOUT = 4
|
||||
STATUS_EX_OUT_LOGOUT = 5
|
||||
# status 0=正常登陆1=正常退出登陆失效2=考试期间输入考试密码登录3=考试期间被挤出登录失效4=同一个浏览器登录导致失效5考试期间进入考试导致其他登录用户失效
|
||||
def generate_new_token
|
||||
self.value = Token.generate_token_value if action != User::SESSION_ACTION
|
||||
end
|
||||
|
||||
def self.get_or_create_permanent_login_token(user, type)
|
||||
token = Token.get_token_from_user(user, type)
|
||||
unless token
|
||||
token = Token.create(:user => user, :action => type)
|
||||
else
|
||||
token.update_attribute(:created_on, Time.now)
|
||||
end
|
||||
token
|
||||
end
|
||||
# 更新session的token的状态值
|
||||
def self.update_token_by_session(user_id,session_id = nil,status = self::STATUS_SELF_LOGOUT)
|
||||
if session_id.present?
|
||||
token = Token.find_by(:action => User::SESSION_ACTION, :user_id => user_id, :value => session_id)
|
||||
if token.present?
|
||||
token.status = status
|
||||
token.save!
|
||||
end
|
||||
else # 同一把所有的token记录状态修改掉并清空对应session_id的缓存
|
||||
self.delete_user_session(user_id,nil,status)
|
||||
end
|
||||
end
|
||||
# 删除用户的session记录
|
||||
def self.delete_user_session(user_id,now_session_id = nil,status = self::STATUS_SELF_LOGOUT)
|
||||
session_store = Rails.application.config.session_store.new(:cache_store, Rails.application.config.session_options)
|
||||
tokens = Token.where(:action => User::SESSION_ACTION, :user_id => user_id,status:[self::STATUS_LOGIN,self::STATUS_EX_LOGIN])
|
||||
tokens = tokens.where.not(value:now_session_id) if now_session_id.present?
|
||||
tokens.each do |token|
|
||||
token.status = status
|
||||
if token.save! # 开始清空session缓存
|
||||
rr = session_store.delete_session(ENV, token.value,Rails.application.config.session_options)
|
||||
Rails.logger.info("调试删除session===#{token.value}===#{rr}")
|
||||
end
|
||||
end
|
||||
end
|
||||
def self.get_token_from_user(user, action)
|
||||
token = Token.where(:action => action, :user_id => user).first
|
||||
unless token
|
||||
token = Token.create!(user_id: user.id, action: action)
|
||||
end
|
||||
token
|
||||
end
|
||||
|
||||
# Return true if token has expired
|
||||
def expired?
|
||||
return Time.now > self.created_on + @@validity_time
|
||||
end
|
||||
|
||||
# Delete all expired tokens
|
||||
def self.destroy_expired
|
||||
Token.delete_all ["action NOT IN (?) AND created_on < ?", ['feeds', 'api', 'autologin'], Time.now - @@validity_time]
|
||||
end
|
||||
|
||||
# Returns the active user who owns the key for the given action
|
||||
def self.find_active_user(action, key, validity_days=nil)
|
||||
user = find_user(action, key, validity_days)
|
||||
if user && user.active?
|
||||
user
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the user who owns the key for the given action
|
||||
def self.find_user(action, key, validity_days=nil)
|
||||
token = find_token(action, key, validity_days)
|
||||
if token
|
||||
token.user
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the token for action and key with an optional
|
||||
# validity duration (in number of days)
|
||||
def self.find_token(action, key, validity_days=nil)
|
||||
action = action.to_s
|
||||
key = key.to_s
|
||||
return nil unless action.present? && key =~ /\A[a-z0-9]+\z/i
|
||||
# if action == User::SESSION_ACTION # 如果是session的则需要判断token是否有效
|
||||
# token = Token.where(value: key, action: action).first
|
||||
# else
|
||||
# token = Token.where(value: key, action: action).first
|
||||
# end
|
||||
token = Token.where(value: key, action: action).first
|
||||
if token && (token.action == action) && (token.value == key) && token.user
|
||||
if validity_days.nil? || (token.created_on > validity_days.days.ago)
|
||||
token
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.generate_token_value
|
||||
Edu::Utils.random_hex(20)
|
||||
end
|
||||
|
||||
def self.delete_user_all_tokens(user)
|
||||
Token.delete_all(user_id: user.id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Removes obsolete tokens (same user and action)
|
||||
def delete_previous_tokens
|
||||
if user && action!='_educoder_session'
|
||||
Token.where(['user_id = ? AND action = ?', user.id, action]).delete_all
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,2 @@
|
||||
class UserAction < ApplicationRecord
|
||||
end
|
||||
@ -0,0 +1,52 @@
|
||||
<%= form_with(model: token, local: true) do |form| %>
|
||||
<% if token.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(token.errors.count, "error") %> prohibited this token from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% token.errors.full_messages.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :user_id %>
|
||||
<%= form.number_field :user_id %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :action %>
|
||||
<%= form.text_field :action %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :status %>
|
||||
<%= form.number_field :status %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :value %>
|
||||
<%= form.text_field :value %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :ip %>
|
||||
<%= form.text_field :ip %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :browser %>
|
||||
<%= form.text_field :browser %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :created_on %>
|
||||
<%= form.date_select :created_on %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= form.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
@ -0,0 +1,2 @@
|
||||
json.extract! token, :id, :user_id, :action, :status, :value, :ip, :browser, :created_on, :created_at, :updated_at
|
||||
json.url token_url(token, format: :json)
|
||||
@ -0,0 +1,6 @@
|
||||
<h1>Editing Token</h1>
|
||||
|
||||
<%= render 'form', token: @token %>
|
||||
|
||||
<%= link_to 'Show', @token %> |
|
||||
<%= link_to 'Back', tokens_path %>
|
||||
@ -0,0 +1,39 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<h1>Tokens</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Action</th>
|
||||
<th>Status</th>
|
||||
<th>Value</th>
|
||||
<th>Ip</th>
|
||||
<th>Browser</th>
|
||||
<th>Created on</th>
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @tokens.each do |token| %>
|
||||
<tr>
|
||||
<td><%= token.user_id %></td>
|
||||
<td><%= token.action %></td>
|
||||
<td><%= token.status %></td>
|
||||
<td><%= token.value %></td>
|
||||
<td><%= token.ip %></td>
|
||||
<td><%= token.browser %></td>
|
||||
<td><%= token.created_on %></td>
|
||||
<td><%= link_to 'Show', token %></td>
|
||||
<td><%= link_to 'Edit', edit_token_path(token) %></td>
|
||||
<td><%= link_to 'Destroy', token, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New Token', new_token_path %>
|
||||
@ -0,0 +1 @@
|
||||
json.array! @tokens, partial: "tokens/token", as: :token
|
||||
@ -0,0 +1,5 @@
|
||||
<h1>New Token</h1>
|
||||
|
||||
<%= render 'form', token: @token %>
|
||||
|
||||
<%= link_to 'Back', tokens_path %>
|
||||
@ -0,0 +1,39 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<strong>User:</strong>
|
||||
<%= @token.user_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Action:</strong>
|
||||
<%= @token.action %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Status:</strong>
|
||||
<%= @token.status %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Value:</strong>
|
||||
<%= @token.value %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Ip:</strong>
|
||||
<%= @token.ip %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Browser:</strong>
|
||||
<%= @token.browser %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Created on:</strong>
|
||||
<%= @token.created_on %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Edit', edit_token_path(@token) %> |
|
||||
<%= link_to 'Back', tokens_path %>
|
||||
@ -0,0 +1 @@
|
||||
json.partial! "tokens/token", token: @token
|
||||
@ -0,0 +1,37 @@
|
||||
<%= form_with(model: user_action, local: true) do |form| %>
|
||||
<% if user_action.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(user_action.errors.count, "error") %> prohibited this user_action from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% user_action.errors.full_messages.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :user_id %>
|
||||
<%= form.number_field :user_id %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :action_type %>
|
||||
<%= form.text_field :action_type %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :action_id %>
|
||||
<%= form.number_field :action_id %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :ip %>
|
||||
<%= form.text_field :ip %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= form.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
@ -0,0 +1,2 @@
|
||||
json.extract! user_action, :id, :user_id, :action_type, :action_id, :ip, :created_at, :updated_at
|
||||
json.url user_action_url(user_action, format: :json)
|
||||
@ -0,0 +1,6 @@
|
||||
<h1>Editing User Action</h1>
|
||||
|
||||
<%= render 'form', user_action: @user_action %>
|
||||
|
||||
<%= link_to 'Show', @user_action %> |
|
||||
<%= link_to 'Back', user_actions_path %>
|
||||
@ -0,0 +1,33 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<h1>User Actions</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Action type</th>
|
||||
<th>Action</th>
|
||||
<th>Ip</th>
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @user_actions.each do |user_action| %>
|
||||
<tr>
|
||||
<td><%= user_action.user_id %></td>
|
||||
<td><%= user_action.action_type %></td>
|
||||
<td><%= user_action.action_id %></td>
|
||||
<td><%= user_action.ip %></td>
|
||||
<td><%= link_to 'Show', user_action %></td>
|
||||
<td><%= link_to 'Edit', edit_user_action_path(user_action) %></td>
|
||||
<td><%= link_to 'Destroy', user_action, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New User Action', new_user_action_path %>
|
||||
@ -0,0 +1 @@
|
||||
json.array! @user_actions, partial: "user_actions/user_action", as: :user_action
|
||||
@ -0,0 +1,5 @@
|
||||
<h1>New User Action</h1>
|
||||
|
||||
<%= render 'form', user_action: @user_action %>
|
||||
|
||||
<%= link_to 'Back', user_actions_path %>
|
||||
@ -0,0 +1,24 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<strong>User:</strong>
|
||||
<%= @user_action.user_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Action type:</strong>
|
||||
<%= @user_action.action_type %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Action:</strong>
|
||||
<%= @user_action.action_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Ip:</strong>
|
||||
<%= @user_action.ip %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Edit', edit_user_action_path(@user_action) %> |
|
||||
<%= link_to 'Back', user_actions_path %>
|
||||
@ -0,0 +1 @@
|
||||
json.partial! "user_actions/user_action", user_action: @user_action
|
||||
@ -0,0 +1,11 @@
|
||||
class CreateUserActions < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :user_actions do |t|
|
||||
t.integer :user_id, comment: "用户id"
|
||||
t.string :action_type, comment: "操作方式"
|
||||
t.integer :action_id, comment: "操作id"
|
||||
t.string :ip, comment: "ip地址"
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,14 @@
|
||||
class CreateTokens < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :tokens do |t|
|
||||
t.integer :user_id, comment: "用户id"
|
||||
t.string :action, comment: "方式"
|
||||
t.integer :status, default: 0, comment: "status 0=正常登陆1=正常退出登陆失效2=考试期间输入考试密码登录3=考试期间被挤出登录失效4=同一个浏览器登录导致失效5考试期间进入考试导致其他登录用户失效"
|
||||
t.string :value, comment: "值"
|
||||
t.string :ip
|
||||
t.string :browser, comment: "登录的游览器"
|
||||
t.date :created_on
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,48 @@
|
||||
require 'test_helper'
|
||||
|
||||
class TokensControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@token = tokens(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get tokens_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_token_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create token" do
|
||||
assert_difference('Token.count') do
|
||||
post tokens_url, params: { token: { action: @token.action, browser: @token.browser, created_on: @token.created_on, ip: @token.ip, status: @token.status, user_id: @token.user_id, value: @token.value } }
|
||||
end
|
||||
|
||||
assert_redirected_to token_url(Token.last)
|
||||
end
|
||||
|
||||
test "should show token" do
|
||||
get token_url(@token)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get edit_token_url(@token)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update token" do
|
||||
patch token_url(@token), params: { token: { action: @token.action, browser: @token.browser, created_on: @token.created_on, ip: @token.ip, status: @token.status, user_id: @token.user_id, value: @token.value } }
|
||||
assert_redirected_to token_url(@token)
|
||||
end
|
||||
|
||||
test "should destroy token" do
|
||||
assert_difference('Token.count', -1) do
|
||||
delete token_url(@token)
|
||||
end
|
||||
|
||||
assert_redirected_to tokens_url
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,48 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UserActionsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user_action = user_actions(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get user_actions_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_user_action_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create user_action" do
|
||||
assert_difference('UserAction.count') do
|
||||
post user_actions_url, params: { user_action: { action_id: @user_action.action_id, action_type: @user_action.action_type, ip: @user_action.ip, user_id: @user_action.user_id } }
|
||||
end
|
||||
|
||||
assert_redirected_to user_action_url(UserAction.last)
|
||||
end
|
||||
|
||||
test "should show user_action" do
|
||||
get user_action_url(@user_action)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get edit_user_action_url(@user_action)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update user_action" do
|
||||
patch user_action_url(@user_action), params: { user_action: { action_id: @user_action.action_id, action_type: @user_action.action_type, ip: @user_action.ip, user_id: @user_action.user_id } }
|
||||
assert_redirected_to user_action_url(@user_action)
|
||||
end
|
||||
|
||||
test "should destroy user_action" do
|
||||
assert_difference('UserAction.count', -1) do
|
||||
delete user_action_url(@user_action)
|
||||
end
|
||||
|
||||
assert_redirected_to user_actions_url
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,19 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
user_id: 1
|
||||
action: MyString
|
||||
status: 1
|
||||
value: MyString
|
||||
ip: MyString
|
||||
browser: MyString
|
||||
created_on: 2023-09-01
|
||||
|
||||
two:
|
||||
user_id: 1
|
||||
action: MyString
|
||||
status: 1
|
||||
value: MyString
|
||||
ip: MyString
|
||||
browser: MyString
|
||||
created_on: 2023-09-01
|
||||
@ -0,0 +1,13 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
user_id: 1
|
||||
action_type: MyString
|
||||
action_id: 1
|
||||
ip: MyString
|
||||
|
||||
two:
|
||||
user_id: 1
|
||||
action_type: MyString
|
||||
action_id: 1
|
||||
ip: MyString
|
||||
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class TokenTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UserActionTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@ -0,0 +1,55 @@
|
||||
require "application_system_test_case"
|
||||
|
||||
class TokensTest < ApplicationSystemTestCase
|
||||
setup do
|
||||
@token = tokens(:one)
|
||||
end
|
||||
|
||||
test "visiting the index" do
|
||||
visit tokens_url
|
||||
assert_selector "h1", text: "Tokens"
|
||||
end
|
||||
|
||||
test "creating a Token" do
|
||||
visit tokens_url
|
||||
click_on "New Token"
|
||||
|
||||
fill_in "Action", with: @token.action
|
||||
fill_in "Browser", with: @token.browser
|
||||
fill_in "Created on", with: @token.created_on
|
||||
fill_in "Ip", with: @token.ip
|
||||
fill_in "Status", with: @token.status
|
||||
fill_in "User", with: @token.user_id
|
||||
fill_in "Value", with: @token.value
|
||||
click_on "Create Token"
|
||||
|
||||
assert_text "Token was successfully created"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "updating a Token" do
|
||||
visit tokens_url
|
||||
click_on "Edit", match: :first
|
||||
|
||||
fill_in "Action", with: @token.action
|
||||
fill_in "Browser", with: @token.browser
|
||||
fill_in "Created on", with: @token.created_on
|
||||
fill_in "Ip", with: @token.ip
|
||||
fill_in "Status", with: @token.status
|
||||
fill_in "User", with: @token.user_id
|
||||
fill_in "Value", with: @token.value
|
||||
click_on "Update Token"
|
||||
|
||||
assert_text "Token was successfully updated"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "destroying a Token" do
|
||||
visit tokens_url
|
||||
page.accept_confirm do
|
||||
click_on "Destroy", match: :first
|
||||
end
|
||||
|
||||
assert_text "Token was successfully destroyed"
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,49 @@
|
||||
require "application_system_test_case"
|
||||
|
||||
class UserActionsTest < ApplicationSystemTestCase
|
||||
setup do
|
||||
@user_action = user_actions(:one)
|
||||
end
|
||||
|
||||
test "visiting the index" do
|
||||
visit user_actions_url
|
||||
assert_selector "h1", text: "User Actions"
|
||||
end
|
||||
|
||||
test "creating a User action" do
|
||||
visit user_actions_url
|
||||
click_on "New User Action"
|
||||
|
||||
fill_in "Action", with: @user_action.action_id
|
||||
fill_in "Action type", with: @user_action.action_type
|
||||
fill_in "Ip", with: @user_action.ip
|
||||
fill_in "User", with: @user_action.user_id
|
||||
click_on "Create User action"
|
||||
|
||||
assert_text "User action was successfully created"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "updating a User action" do
|
||||
visit user_actions_url
|
||||
click_on "Edit", match: :first
|
||||
|
||||
fill_in "Action", with: @user_action.action_id
|
||||
fill_in "Action type", with: @user_action.action_type
|
||||
fill_in "Ip", with: @user_action.ip
|
||||
fill_in "User", with: @user_action.user_id
|
||||
click_on "Update User action"
|
||||
|
||||
assert_text "User action was successfully updated"
|
||||
click_on "Back"
|
||||
end
|
||||
|
||||
test "destroying a User action" do
|
||||
visit user_actions_url
|
||||
page.accept_confirm do
|
||||
click_on "Destroy", match: :first
|
||||
end
|
||||
|
||||
assert_text "User action was successfully destroyed"
|
||||
end
|
||||
end
|
||||
Loading…
Reference in new issue