#5092 fix-4959

Merged
chenshihai merged 23 commits from fix-4959 into V20240109 3 months ago
  1. +1
    -0
      models/models.go
  2. +32
    -0
      models/user_other_info.go
  3. +1
    -0
      modules/context/context.go
  4. +7
    -1
      options/locale/locale_en-US.ini
  5. +7
    -1
      options/locale/locale_zh-CN.ini
  6. +3
    -2
      routers/routes/routes.go
  7. +46
    -0
      routers/user/auth.go
  8. +5
    -1
      templates/base/footer.tmpl
  9. +1
    -1
      templates/terms.tmpl
  10. +16
    -0
      templates/user/auth/network_security.tmpl
  11. +52
    -0
      web_src/js/index.js
  12. +3
    -0
      web_src/less/openi.less

+ 1
- 0
models/models.go View File

@@ -195,6 +195,7 @@ func init() {
new(UserBusinessAnalysisYesterday),
new(UserBusinessAnalysisLastWeek),
new(UserLoginLog),
new(UserOtherInfo),
new(UserMetrics),
new(UserAnalysisPara),
new(Invitation),


+ 32
- 0
models/user_other_info.go View File

@@ -0,0 +1,32 @@
package models

import (
"code.gitea.io/gitea/modules/timeutil"
)

type UserOtherInfo struct {
ID int64 `xorm:"pk autoincr"`
UId int64 `xorm:"NOT NULL"`
IsNewAgree bool
CreatedUnix timeutil.TimeStamp `xorm:"created"`
}

func GetNewAgreeByUID(uid int64) bool {
userOtherInfo := new(UserOtherInfo)
has, err := xStatistic.Where("u_id=?", uid).Desc("id").Limit(1).Get(userOtherInfo)
if err != nil || !has {
return false
}
return userOtherInfo.IsNewAgree
}

func SaveUserOtherInfoToDb(uid int64) {
statictisSess := xStatistic.NewSession()
defer statictisSess.Close()

userOtherInfo := &UserOtherInfo{
UId: uid,
IsNewAgree: true,
}
statictisSess.Insert(userOtherInfo)
}

+ 1
- 0
modules/context/context.go View File

@@ -313,6 +313,7 @@ func Contexter() macaron.Handler {
ctx.Data["SignedUserName"] = ctx.User.Name
ctx.Data["IsAdmin"] = ctx.User.IsAdmin
ctx.Data["IsOperator"] = ctx.User.IsOperator
ctx.Data["IsNewAgree"] = models.GetNewAgreeByUID(ctx.User.ID)
c.Data["SignedUserName"] = ctx.User.Name
} else {
ctx.Data["SignedUserID"] = int64(0)


+ 7
- 1
options/locale/locale_en-US.ini View File

@@ -416,7 +416,13 @@ change_email = Change email
change_email_address = Change email address
new_email_address = New email address
openi_community_really_awesome = OpenI, Really Awesome!

protocol_header=Please read the following content carefully:
protocol_title=Dear OpenI User
protocol_context=Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you check and agree, you can continue to use our services. Thank you for your cooperation and understanding.
protocol_context_sub=For more agreement content, please refer to the<u><font color="# 3291f8"><a href="/home/term" target="_blank">《Openl Qizhi Community AI Collaboration Platform Usage Agreement》</a></font></u>
protocol_confirm=Agree and continue
protocol_cancel=Disagree, exit
protocol_update=Reading protocol updates
[phone]
format_err=The format of phone number is wrong.
query_err=Fail to query phone number, please try again later.


+ 7
- 1
options/locale/locale_zh-CN.ini View File

@@ -419,7 +419,13 @@ change_email=修改邮箱
change_email_address=修改邮箱地址
new_email_address=新邮箱地址
openi_community_really_awesome=启智社区 确实给力

protocol_header=请仔细阅读下方内容:
protocol_title=尊敬的启智用户
protocol_context=感谢您一直以来对Openl启智社区AI协作平台的支持。为了保障您的使用权益和确保网络安全,我们于2024年1月份更新了《Openl启智社区AI协作平台使用协议》。更新后的协议明确了用户<font color="#ff2525">禁止使用内网穿透工具</font>的条例。在您勾选同意后,便可以继续使用我们的服务。感谢您的合作与理解。
protocol_context_sub=更多协议内容,请参考<u><font color="#3291f8"><a href="/home/term" target="_blank">《Openl启智社区AI协作平台使用协议》</a></font></u>
protocol_confirm=同意并继续
protocol_cancel=不同意,退出
protocol_update=阅读协议更新
[phone]
format_err=手机号格式错误。
query_err=查询手机号失败,请稍后再试。


+ 3
- 2
routers/routes/routes.go View File

@@ -370,6 +370,8 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/home/notice", routers.HomeNoticeTmpl)
m.Get("/home/privacy", routers.HomePrivacy)

m.Post("/user/saveOtherInfo", user.SaveUserOtherInfo, reqSignIn)

m.Group("/modelsquare", func() {
m.Get("/main", repo.ModelSquareTmpl)
m.Get("/main_query_data", repo.ModelSquareData)
@@ -404,7 +406,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/demand", routers.ComputingPowerDemand)
m.Get("/domestic", routers.ComputingPowerDomestic)
}, ignSignIn)
operationReq := context.Toggle(&context.ToggleOptions{SignInRequired: true, OperationRequired: true})
m.Group("/explore", func() {
m.Get("", func(ctx *context.Context) {
@@ -474,7 +476,6 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/login/cloud_brain", user.SignInCloudBrain)
m.Post("/login/cloud_brain", bindIgnErr(auth.SignInForm{}), user.SignInCloudBrainPost)
m.Post("/login", bindIgnErr(auth.SignInForm{}), user.SignInPost)

m.Get("/login/phone", user.SignInPhone)
m.Post("/login/phone", bindIgnErr(auth.PhoneNumberCodeForm{}), user.SignInPhonePost)
m.Group("", func() {


+ 46
- 0
routers/user/auth.go View File

@@ -192,6 +192,51 @@ func setRSAContext(ctx *context.Context) {
}
}

func GetUserOtherInfo(ctx *context.Context) {
userName := ctx.Query("userName")
phone := ctx.Query("phone")
var err error
var user *models.User
if userName != "" {
user, err = models.GetUserByName(userName)
}
if phone != "" {
user, err = models.GetUserByPhoneNumber(phone)
}
re := make(map[string]interface{}, 0)
if err != nil || user == nil {
re["result_code"] = "-1"
ctx.JSON(200, re)
} else {
re["result_code"] = "0"
re["agree"] = models.GetNewAgreeByUID(user.ID)
ctx.JSON(200, re)
}
}

func SaveUserOtherInfo(ctx *context.Context) {
userName := ctx.Query("userName")
phone := ctx.Query("phone")
var err error
var user *models.User
if userName != "" {
user, err = models.GetUserByName(userName)
}
if phone != "" {
user, err = models.GetUserByPhoneNumber(phone)
}
re := make(map[string]interface{}, 0)
if err != nil || user == nil {
re["result_code"] = "-1"
ctx.JSON(200, re)
} else {
re["result_code"] = "0"
models.SaveUserOtherInfoToDb(user.ID)
ctx.Data["IsNewAgree"] = true
ctx.JSON(200, re)
}
}

// SignInCloudBrain render sign in page
func SignInCloudBrain(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("sign_in")
@@ -251,6 +296,7 @@ func SignInPhonePost(ctx *context.Context, form auth.PhoneNumberCodeForm) {
}
return
}

models.SaveLoginInfoToDb(ctx.Req.Request, u)

handleSignIn(ctx, u, form.Remember)


+ 5
- 1
templates/base/footer.tmpl View File

@@ -9,7 +9,9 @@
</div>

{{template "custom/body_outer_post" .}}

{{if not .IsNewAgree}}
{{template "user/auth/network_security" .}}
{{end}}
{{template "base/footer_content" .}}

<script src="{{StaticUrlPrefix}}/js/jquery.js?v={{MD5 AppVer}}"></script>
@@ -46,6 +48,8 @@
<script src="{{StaticUrlPrefix}}/fomantic/semantic.min.js?v={{MD5 AppVer}}"></script>
<script src="{{StaticUrlPrefix}}/js/index.js?v={{MD5 AppVer}}"></script>
{{template "custom/footer" .}}

{{if .PageIsHome}}

<!--script src="https://www.jq22.com/jquery/jquery-1.10.2.js?v={{MD5 AppVer}}"></script-->


+ 1
- 1
templates/terms.tmpl View File

@@ -21,7 +21,7 @@
您充分理解并同意,您在使用平台服务时,应当遵守所有中华人民共和国的法律、法规、规章制度、规范、政策、行政命令、强制标准及行业标准等(统称为“法律法规”)。除非法律法规允许且启智社区事先书面许可,您不得从事以下活动,也不得同意、授权或指示任何第三人从事包括但不限于以下内容的活动:
<br>
(1) 对平台服务进行挖矿、逆向工程、反编辑等恶意行为损坏平台服务相关内容与数据,或不正当手段获取原始数据和其他数据等;<br>
(2) 对平台服务或者平台服务运行过程中释放出的任何数据或其他数据及平台服务运行过程中的交互数据进行复制、更改、修改等操作,包括但不限于使用插件、外挂或非经授权的第三方工具或服务接入平台服务和相关系统;
(2) 对平台服务或者平台服务运行过程中释放出的任何数据或其他数据及平台服务运行过程中的交互数据进行复制、更改、修改等操作,包括但不限于使用插件、外挂或非经授权的第三方工具(如内网穿透工具)或服务接入平台服务和相关系统;
<br>
(3) 宣扬或提供关于非法行为的说明信息、宣扬针对任何团体或个人的人身伤害或传播任何病毒、蠕虫、缺陷、特洛伊木马或其他具有破坏性的内容等;<br>
(4) 删除本平台服务中包含的任何版权声明、商标声明或其他所有权声明;包括但不限于任何有损本平台一切相关知识产权的行为;<br>


+ 16
- 0
templates/user/auth/network_security.tmpl View File

@@ -0,0 +1,16 @@
<div class="ui tiny modal network-security" data-update='{{.i18n.Tr "auth.protocol_update"}}' data-confirm='{{.i18n.Tr "auth.protocol_confirm"}}'>
<div class="header" style="padding: 1rem;background-color: rgba(240, 240, 240, 100);font-size: 1rem;">{{.i18n.Tr "auth.protocol_header"}}</div>
<div class="content">
<p>{{.i18n.Tr "auth.protocol_title"}}</p>
<p style="text-indent: 2rem;">
{{.i18n.Tr "auth.protocol_context" | Safe}}
</p>
<p></p>
<p>{{.i18n.Tr "auth.protocol_context_sub" | Safe}}</p>
</div>
<div class="actions" style="border: none;text-align: center;padding: 0 1rem 2rem 1rem;background-color: #fff;">
<div class="ui green approve button">{{.i18n.Tr "auth.protocol_confirm"}}</div>
<div class="ui blank cancel button">{{.i18n.Tr "auth.protocol_cancel"}}</div>
</div>
</div>
</div>

+ 52
- 0
web_src/js/index.js View File

@@ -5394,3 +5394,55 @@ initTopToHome();
$(".question.circle.icon").hover(function () {
$(this).popup("show");
});


function initAddUsageAgreement() {
function showLoginProtocolDialog(userName) {
let cutDown = 5
let updateTips = $('.ui.modal.network-security').data('update')
let confirmTips = $('.ui.modal.network-security').data('confirm')
$('.ui.modal.network-security')
.modal({
centered: false,
onShow: function () {
$('.ui.dimmer').css({ "background-color": "rgb(136, 136, 136,0.7)" })
$('.network-security .approve').addClass('disabled').text(`${updateTips} (${cutDown}s)`)
var timer = setInterval(function () {
cutDown--
$('.network-security .approve').addClass('disabled').text(`${updateTips} (${cutDown}s)`)
if (cutDown <= 0) {
$('.network-security .approve').removeClass('disabled').text(confirmTips)
clearInterval(timer);
}
}, 1000);
},
onHide:function(){
},
onApprove: async function ($element) {
try {
const res = await postSaveProtocolInfo(userName)
if (res?.data?.result_code === "0") {
return true
} else {
return false
}
} catch (err) {
console.log(err)
}
},
onDeny: function () {
$(".link-action").trigger("click");
},
})
.modal('setting', 'closable', false)
.modal('show')
}
async function postSaveProtocolInfo(userName) {
let params = {userName:userName}
return axios.post(`${AppSubUrl}/user/saveOtherInfo`,qs.stringify(params))
}
if ($('meta[name="_uid"]').length) {
showLoginProtocolDialog($('meta[name="_uid"]').attr('content-ext'))
}
}
initAddUsageAgreement()

+ 3
- 0
web_src/less/openi.less View File

@@ -1616,4 +1616,7 @@ i.SUCCEEDED {
.ui.secondary.menu #navbar .right.menu .ui.item.simple {
padding: 0.78571429em 0.42857143em;
margin: 0 0.15714286em;
}
.ui.tiny.modal.network-security{
top:20vh !important;
}

Loading…
Cancel
Save