|
@@ -8,6 +8,7 @@ using IdentityModel;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
+using Org.BouncyCastle.Ocsp;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
@@ -39,8 +40,6 @@ namespace HiTeachCE.Controllers
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 获取讲师列表
|
|
|
/// </summary>
|
|
@@ -48,47 +47,65 @@ namespace HiTeachCE.Controllers
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("list")]
|
|
|
[Authorize(Roles = "root")]
|
|
|
- public BaseJosnRPCResponse list(JosnRPCRequest<Dictionary<string, string>> request)
|
|
|
+ public BaseJosnRPCResponse List(PaginationJosnRPCRequest<Dictionary<string, string>> request)
|
|
|
{
|
|
|
// request.@params.TryAdd("PartitionKey", request.lang);
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
List<Lecturer> lecturers = new List<Lecturer>();
|
|
|
Expression<Func<Lecturer, bool>> linq = null;
|
|
|
- if (request.@params.TryGetValue("cellphone", out string cellphone) && !string.IsNullOrEmpty(cellphone))
|
|
|
+ if (request.@params.data.TryGetValue("cellphone", out string cellphone) && !string.IsNullOrEmpty(cellphone))
|
|
|
{
|
|
|
linq = m => m.cellphone == cellphone;
|
|
|
}
|
|
|
- if (request.@params.TryGetValue("account", out string account) && !string.IsNullOrEmpty(account))
|
|
|
+ if (request.@params.data.TryGetValue("account", out string account) && !string.IsNullOrEmpty(account))
|
|
|
{
|
|
|
linq = m => m.account == account;
|
|
|
}
|
|
|
- if (request.@params.TryGetValue("username", out string username) && !string.IsNullOrEmpty(username))
|
|
|
+ if (request.@params.data.TryGetValue("username", out string username) && !string.IsNullOrEmpty(username))
|
|
|
{
|
|
|
linq = m => m.username.Contains(username);
|
|
|
}
|
|
|
- if (request.@params.TryGetValue("id", out string id) && !string.IsNullOrEmpty(id))
|
|
|
+ if (request.@params.data.TryGetValue("id", out string id) && !string.IsNullOrEmpty(id))
|
|
|
{
|
|
|
linq = m => m.id==id;
|
|
|
}
|
|
|
if (linq != null)
|
|
|
{
|
|
|
- lecturers = lecturerService.GetList(linq);
|
|
|
+ lecturers = lecturerService.GetPageList(linq,request.@params.page);
|
|
|
}
|
|
|
lecturers.ForEach(x => { x.password = null; });
|
|
|
- return builder.Data(lecturers).build();
|
|
|
+ return builder.Data(lecturers).Page(request.@params.page).build();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 更新讲师
|
|
|
+ /// 更新自己的资料
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
- [HttpPost("update")]
|
|
|
- [Authorize(Roles = "root")]
|
|
|
- public BaseJosnRPCResponse update(JosnRPCRequest<Lecturer> request)
|
|
|
+ [HttpPost("updateSelf")]
|
|
|
+ [Authorize(Roles = "all")]
|
|
|
+ public BaseJosnRPCResponse UpdateSelf(JosnRPCRequest<Lecturer> request)
|
|
|
{
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
+ string unionid = GetLoginUser(JwtClaimTypes.Id);
|
|
|
Lecturer lecturer = lecturerService.GetById(request.@params.id);
|
|
|
+ bool b = false;
|
|
|
+ //确保更新的是自己
|
|
|
+ if (unionid.Equals(request.@params.unionid ) && unionid.Equals(lecturer.unionid))
|
|
|
+ {
|
|
|
+ b = UpdateLecture(request, lecturer);
|
|
|
+ }
|
|
|
+ return builder.Data(b).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 更新
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request">修改后的</param>
|
|
|
+ /// <param name="lecturer">修改前的</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private bool UpdateLecture(JosnRPCRequest<Lecturer> request ,Lecturer lecturer)
|
|
|
+ {
|
|
|
bool b = false;
|
|
|
if (lecturer != null)
|
|
|
{
|
|
@@ -110,65 +127,92 @@ namespace HiTeachCE.Controllers
|
|
|
request.@params.areaCode = lecturer.areaCode;
|
|
|
b = lecturerService.Update(request.@params);
|
|
|
}
|
|
|
- return builder.Data(b).build();
|
|
|
+ return b;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/// <summary>
|
|
|
- /// 获取知识
|
|
|
+ /// 更新讲师
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
- [HttpGet("GetId")]
|
|
|
- public BaseJosnRPCResponse GetList()
|
|
|
+ [HttpPost("update")]
|
|
|
+ [Authorize(Roles = "root")]
|
|
|
+ public BaseJosnRPCResponse Update(JosnRPCRequest<Lecturer> request)
|
|
|
{
|
|
|
- // request.@params.TryAdd("PartitionKey", request.lang);
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
- List<Lecturer> data = lecturerService.GetList();
|
|
|
- return builder.Data(Guid.NewGuid()).build();
|
|
|
+ Lecturer lecturer = lecturerService.GetById(request.@params.id);
|
|
|
+ bool b = UpdateLecture(request, lecturer);
|
|
|
+ return builder.Data(b).build();
|
|
|
}
|
|
|
- ///// <summary>
|
|
|
- ///// 获取知识
|
|
|
- ///// </summary>
|
|
|
- ///// <param name="request"></param>
|
|
|
- ///// <returns></returns>
|
|
|
- //[HttpPost("GetList")]
|
|
|
- //[Authorize(Roles = "admin")]
|
|
|
- //public BaseJosnRPCResponse GetList(JosnRPCRequest<Dictionary<string, object>> request)
|
|
|
- //{
|
|
|
- // // request.@params.TryAdd("PartitionKey", request.lang);
|
|
|
- // JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
- // List<Lecturer> data = lecturerService.GetList() ;
|
|
|
- // return builder.Data(Guid.NewGuid()).build();
|
|
|
- //}
|
|
|
/// <summary>
|
|
|
- /// 获取知识
|
|
|
+ /// 注册用户
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
- [HttpPost("GetList1")]
|
|
|
- [Authorize(Policy = "admin")]
|
|
|
- public BaseJosnRPCResponse GetList1(JosnRPCRequest<Dictionary<string, object>> request)
|
|
|
+ [HttpPost("register")]
|
|
|
+ public BaseJosnRPCResponse Register(JosnRPCRequest<RegisterDto> request)
|
|
|
{
|
|
|
- // request.@params.TryAdd("PartitionKey", request.lang);
|
|
|
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
- List<Lecturer> data = lecturerService.GetList();
|
|
|
- return builder.Data(Guid.NewGuid()).build();
|
|
|
- }/// <summary>
|
|
|
- /// 获取知识
|
|
|
- /// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpPost("GetList2")]
|
|
|
- [Authorize]
|
|
|
- public BaseJosnRPCResponse GetList2(JosnRPCRequest<Dictionary<string, object>> request)
|
|
|
- {
|
|
|
- // request.@params.TryAdd("PartitionKey", request.lang);
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
+ if (RedisHelper.Exists("ticket:" + request.@params.ticket))
|
|
|
+ {
|
|
|
+ if (request.@params.user != null)
|
|
|
+ {
|
|
|
+ string[] phone = RedisHelper.HVals("ticket:" + request.@params.ticket);
|
|
|
+ if (phone.IsNotEmpty())
|
|
|
+ {
|
|
|
+ if (!request.@params.user.cellphone.Equals(phone[0]))
|
|
|
+ {
|
|
|
+ throw new BizException("手机号与凭证不匹配!", 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new BizException("凭证无效!", 2);
|
|
|
+ }
|
|
|
+ Expression<Func<Lecturer, bool>> linq = null;
|
|
|
+ linq = m => m.cellphone == request.@params.user.cellphone || m.account == request.@params.user.account;
|
|
|
+ List<Lecturer> lecturers = lecturerService.GetList(linq);
|
|
|
+ if (lecturers.IsNotEmpty())
|
|
|
+ {
|
|
|
+ throw new BizException("手机号或账号已经存在!", 2);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ request.@params.user.id = Guid.NewGuid().ToString();
|
|
|
+ request.@params.user.unionid = Guid.NewGuid().ToString("N");
|
|
|
+ request.@params.user.areaCode = "86";
|
|
|
+ request.@params.user.status = 1;
|
|
|
+ request.@params.user.registerTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
|
|
|
|
|
|
- return builder.Data(Guid.NewGuid()).build();
|
|
|
+ if (request.@params.user.password == null)
|
|
|
+ {
|
|
|
+ request.@params.user.password = "";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ request.@params.user.password = BCrypt.Net.BCrypt.HashPassword(request.@params.user.password);
|
|
|
+ }
|
|
|
+ bool ib = lecturerService.Insert(request.@params.user);
|
|
|
+ if (ib)
|
|
|
+ {
|
|
|
+ return builder.Data(ib).build();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new BizException("注册失败!", 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new BizException("参数错误!", 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new BizException("短信验证过期!", 2);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|