Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
jingquan huang 5 years ago
commit ee515e97e5

@ -34,8 +34,8 @@ class AccountsController < ApplicationController
# check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60)
# todo 上线前请删除万能验证码"513231"
if code != "513231"
tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) > 10*60
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
end
code = generate_identifier User, 8
@ -55,6 +55,10 @@ class AccountsController < ApplicationController
container_type: pre == 'p' ? 'Phone' : 'Mail',
score: 500
)
# 注册时,记录是否是引流用户
ip = request.remote_ip
ua = UserAgent.find_by_ip(ip)
ua.update_column(:agent_type, UserAgent::USER_REGISTER) if ua
successful_authentication(@user)
session[:user_id] = @user.id
normal_status("注册成功")
@ -68,6 +72,15 @@ class AccountsController < ApplicationController
# 用户登录
def login
@user = User.try_to_login(params[:login], params[:password])
if @user
# user is already in local database
return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked?
return normal_status(-2, "错误的账号或密码") unless @user.check_password?(params[:password].to_s)
else
return normal_status(-2, "错误的账号或密码")
end
@user.update_column(:last_login_on, Time.now)
successful_authentication(@user)
@ -90,8 +103,8 @@ class AccountsController < ApplicationController
verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last
user = User.find_by_mail(email) #这里有问题应该是为email,而不是mail 6.13-hs
end
tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) > 10*60
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation]
if user.save!
@ -110,7 +123,7 @@ class AccountsController < ApplicationController
# generate a key and set cookie if autologin
set_autologin_cookie(user)
UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id))
UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id), :ip => request.remote_ip)
# 注册完成后有一天的试用申请
UserDayCertification.create(user_id: user.id, status: 1)
@ -133,7 +146,7 @@ class AccountsController < ApplicationController
end
def logout
UserAction.create(action_id: User.current.id, action_type: "Logout", user_id: User.current.id)
UserAction.create(action_id: User.current.id, action_type: "Logout", user_id: User.current.id, :ip => request.remote_ip)
session[:user_id] = nil
logout_user
render :json => {status: 1, message: "退出成功!"}

@ -249,7 +249,7 @@ class ChallengesController < ApplicationController
next_challenge.update_attribute(:position, next_challenge.position - 1)
# 关卡位置被修改,需要修改脚本
script = modify_shixun_script @shixun, @shixun.evaluate_script
@shixun.update_column(:evaluate_script, script)
@shixun.shixun_info.update_column(:evaluate_script, script)
end
def index_up
@ -259,7 +259,7 @@ class ChallengesController < ApplicationController
last_challenge.update_attribute(:position, last_challenge.position + 1)
# 关卡位置被修改,需要修改脚本
script = modify_shixun_script @shixun, @shixun.evaluate_script
@shixun.update_column(:evaluate_script, script)
@shixun.shixun_info.update_column(:evaluate_script, script)
end
def destroy
@ -270,7 +270,7 @@ class ChallengesController < ApplicationController
@challenge.destroy
# 关卡位置被删除,需要修改脚本
script = modify_shixun_script @shixun, @shixun.evaluate_script
@shixun.update_column(:evaluate_script, script)
@shixun.shixun_info.update_column(:evaluate_script, script)
end

@ -47,7 +47,8 @@ module Searchable::Shixun
author_name: user.real_name,
author_school_name: user.school_name,
visits_count: visits,
challenges_count: challenges_count
challenges_count: challenges_count,
study_count: myshixuns_count
}
end

@ -507,14 +507,6 @@ class User < ApplicationRecord
user = find_by_login(login)
end
if user
# user is already in local database
raise Educoder::TipException.new(-2, "违反平台使用规范,账号已被锁定") if user.locked?
raise Educoder::TipException.new(-2, "错误的账号或密码") unless user.check_password?(password)
else
raise Educoder::TipException.new(-2, "错误的账号或密码")
end
user
rescue => text
raise text

@ -0,0 +1,6 @@
class UserAgent < ApplicationRecord
has_many :user_actionss, :foreign_key => "ip", :primary_key => "ip"
USER_AD = 1 # 广告宣传的引流
USER_REGISTER = 2 # 引流注册
USER_COMPETITION = 3 # 引流参加竞赛
end

@ -20,7 +20,7 @@ module ElasticsearchAble
def highlight_options
{
fragment_size: EduSetting.get('es_highlight_fragment_size') || 30,
tag: '<span>'
tag: '<span class="highlight">'
}
end

@ -1,5 +1,5 @@
json.id @user.id
json.name @user.homepage_name
json.name @user.full_name
json.avatar_url url_to_avatar(@user)
json.is_logged_user @user.logged_user?
json.experience @user.experience

@ -19,15 +19,13 @@ class MigrateCourseMembers < ActiveRecord::Migration[5.2]
ActiveRecord::Base.transaction do
begin
Member.where("course_id != -1").find_each do |member|
if member.course && member.user
puts(member.id)
member.member_roles.each do |role|
course_member_role = role.role_id == 3 ? 1 : (role.role_id == 9 ? 2 : (role.role_id == 7 ? 3 : 4))
member_group_id = role.role_id == 10 ? member.course_group_id : 0
CourseMember.create!(course_id: member.course_id, user_id: member.user_id, course_group_id: member_group_id.to_i,
graduation_group_id: member.graduation_group_id.to_i, role: course_member_role, is_active: role.is_current)
end
Member.where("course_id != -1").includes(:member_roles).find_each(batch_size: 500) do |member|
puts(member.id)
member.member_roles.each do |role|
course_member_role = role.role_id == 3 ? 1 : (role.role_id == 9 ? 2 : (role.role_id == 7 ? 3 : 4))
member_group_id = role.role_id == 10 ? member.course_group_id : 0
CourseMember.create!(course_id: member.course_id, user_id: member.user_id, course_group_id: member_group_id,
graduation_group_id: member.graduation_group_id, role: course_member_role, is_active: role.is_current)
end
end
rescue Exception => e

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe UserAgent, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save