|
@@ -15,6 +15,7 @@ using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
|
|
|
using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
|
|
|
using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
|
using TEAMModelOS.SDK.Helper.Common.JsonHelper;
|
|
|
+using TEAMModelOS.SDK.Helper.Security.ShaHash;
|
|
|
|
|
|
namespace HiTeachCE.Controllers
|
|
|
{
|
|
@@ -22,6 +23,8 @@ namespace HiTeachCE.Controllers
|
|
|
[ApiController]
|
|
|
public class LoginController : Controller
|
|
|
{
|
|
|
+
|
|
|
+ public static int smsTTL = 4 * 60;
|
|
|
private readonly LecturerService lecturerService;
|
|
|
private readonly OrganizationService organizationService;
|
|
|
private readonly MemberService memberService;
|
|
@@ -31,12 +34,33 @@ namespace HiTeachCE.Controllers
|
|
|
organizationService = organization;
|
|
|
memberService = member;
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 登录
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("auth")]
|
|
|
+ public async Task<BaseJosnRPCResponse> auth(JosnRPCRequest<Dictionary<string, string>> request) {
|
|
|
+ JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
+ if (request.@params.TryGetValue("cellphone", out string cellphone) &&
|
|
|
+ request.@params.TryGetValue("smscode", out string smscode)&&
|
|
|
+ //上课模式
|
|
|
+ request.@params.TryGetValue("model", out string model)
|
|
|
+ ) {
|
|
|
+
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 登录
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
- [HttpPost]
|
|
|
+ [HttpPost("phoneLogin")]
|
|
|
public async Task<BaseJosnRPCResponse> PhoneLogin(JosnRPCRequest<Dictionary<string, string>> request)
|
|
|
{
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
@@ -44,6 +68,12 @@ namespace HiTeachCE.Controllers
|
|
|
request.@params.TryGetValue("smscode", out string smscode)
|
|
|
)
|
|
|
{
|
|
|
+ string ticket = ShaHashHelper.GetSHA1(cellphone + smscode);
|
|
|
+ if (RedisHelper.Exists("ticket:" + ticket)) {
|
|
|
+ Dictionary<string ,object> dict= userValid(cellphone);
|
|
|
+ dict.Add("ticket", ticket);
|
|
|
+ return builder.Data(dict).build();
|
|
|
+ }
|
|
|
if (RedisHelper.Exists(cellphone))
|
|
|
{
|
|
|
string[] vals = RedisHelper.HVals<string>(cellphone);
|
|
@@ -58,42 +88,12 @@ namespace HiTeachCE.Controllers
|
|
|
{
|
|
|
if (json.GetBoolean())
|
|
|
{
|
|
|
- Expression<Func<Lecturer, bool>> linq = null;
|
|
|
- linq = m => m.cellphone == cellphone;
|
|
|
- List<Lecturer> lecturers = lecturerService.GetList(linq);
|
|
|
- if (lecturers.IsNotEmpty())
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Random random = new Random();
|
|
|
- string seed = new string(Constant.az09);
|
|
|
- string pfx = "";
|
|
|
- for (int i = 0; i < 4; i++) {
|
|
|
- string c = seed.ToCharArray()[random.Next(0, seed.Length)]+"";
|
|
|
- seed.Replace(c, "");
|
|
|
- pfx = pfx + c;
|
|
|
- }
|
|
|
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
|
|
- long time= Convert.ToInt64(ts.TotalSeconds);
|
|
|
- return builder.Data(new Dictionary<string, object> {
|
|
|
- { "new",true},
|
|
|
- { "user",new Lecturer
|
|
|
- {
|
|
|
- id= Guid.NewGuid().ToString(),
|
|
|
- unionid= Guid.NewGuid().ToString("N"),
|
|
|
- username=cellphone+"手机用户",
|
|
|
- password="",
|
|
|
- account="hitmd-"+cellphone.Substring(cellphone.Length-4,4)+"#"+pfx,
|
|
|
- areaCode="86",
|
|
|
- registerTime=time,
|
|
|
- status=1,
|
|
|
- setaccount=0
|
|
|
- }
|
|
|
- }
|
|
|
- }).build();
|
|
|
- }
|
|
|
+ ///验证通过 验证信息存放在reids
|
|
|
+ RedisHelper.HSet("ticket:" + ticket, cellphone, smscode);
|
|
|
+ RedisHelper.Expire("ticket:" + ticket, smsTTL);
|
|
|
+ Dictionary<string, object> dict = userValid(cellphone);
|
|
|
+ dict.Add("ticket", ticket);
|
|
|
+ return builder.Data(dict).build();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -122,21 +122,76 @@ namespace HiTeachCE.Controllers
|
|
|
|
|
|
//如果验证通过则将验证信息缓存至redis 以防再次远程验证不通过
|
|
|
|
|
|
- string uid = "";
|
|
|
- List<Organization> organizations = GetOrgByUid(uid);
|
|
|
- return builder.Data(organizations).build();
|
|
|
+ //string uid = "";
|
|
|
+ //List<Organization> organizations = GetOrgByUid(uid);
|
|
|
+ //return builder.Data(organizations).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Dictionary<string ,object> userValid( string cellphone)
|
|
|
+ {
|
|
|
+ Expression<Func<Lecturer, bool>> linq = null;
|
|
|
+ linq = m => m.cellphone == cellphone;
|
|
|
+ List<Lecturer> lecturers = lecturerService.GetList(linq);
|
|
|
+ if (lecturers.IsNotEmpty())
|
|
|
+ {
|
|
|
+ //用户存在则返回组织机构信息
|
|
|
+ List<Organization> organizations = GetOrgByUid(lecturers[0].unionid);
|
|
|
+ if (organizations.IsNotEmpty())
|
|
|
+ {
|
|
|
+ return new Dictionary<string, object> {
|
|
|
+ { "status",2},
|
|
|
+ { "org",organizations},
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return new Dictionary<string, object> { { "status", 3 }, { "org", organizationService.GetByIds(new string[] { "babca5a0-97f0-434d-b72a-98c207215085" }) } };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //不存在用户则新增一个
|
|
|
+ Random random = new Random();
|
|
|
+ string seed = new string(Constant.az09);
|
|
|
+ string pfx = "";
|
|
|
+ for (int i = 0; i < 4; i++)
|
|
|
+ {
|
|
|
+ string c = seed.ToCharArray()[random.Next(0, seed.Length)] + "";
|
|
|
+ seed.Replace(c, "");
|
|
|
+ pfx = pfx + c;
|
|
|
+ }
|
|
|
+ return new Dictionary<string, object> {
|
|
|
+ { "status",1},
|
|
|
+ { "user",new Lecturer
|
|
|
+ {
|
|
|
+ id= Guid.NewGuid().ToString(),
|
|
|
+ unionid= Guid.NewGuid().ToString("N"),
|
|
|
+ username=cellphone+"手机用户",
|
|
|
+ password="",
|
|
|
+ account="hitmd-"+cellphone.Substring(cellphone.Length-4,4)+"#"+pfx,
|
|
|
+ areaCode="86",
|
|
|
+ registerTime=new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(),
|
|
|
+ status=1,
|
|
|
+ setaccount=0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private List<Organization> GetOrgByUid(string uid)
|
|
|
{
|
|
|
Expression<Func<Member, bool>> mlinq = null;
|
|
|
- mlinq = m => m.unionid == uid;
|
|
|
+ mlinq = m => m.unionid == uid && m.expires > 0 && m.status == 1;
|
|
|
List<Member> members = memberService.GetList(mlinq);
|
|
|
- Expression<Func<Organization, bool>> olinq = null;
|
|
|
- olinq = o => members.Select(x => x.orgCode).ToList().Contains(o.code);
|
|
|
- List<Organization> organizations = organizationService.GetList(olinq);
|
|
|
- ///返回前端后倒计时10秒自动选择组织机构,以防再次验证的时候 reids过期
|
|
|
- return organizations;
|
|
|
+ if (members.IsNotEmpty())
|
|
|
+ {
|
|
|
+ Expression<Func<Organization, bool>> olinq = null;
|
|
|
+ olinq = o => members.Select(x => x.orgCode).ToList().Contains(o.code) && o.status == 1;
|
|
|
+ List<Organization> organizations = organizationService.GetList(olinq);
|
|
|
+ ///返回前端后倒计时10秒自动选择组织机构,以防再次验证的时候 reids过期
|
|
|
+ return organizations;
|
|
|
+ }
|
|
|
+ else { return null; }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -202,7 +257,7 @@ namespace HiTeachCE.Controllers
|
|
|
string msgidstr = msgid.GetString();
|
|
|
RedisHelper.Del(new string[] { key });
|
|
|
RedisHelper.HSet(key, msgidstr, msgidstr);
|
|
|
- RedisHelper.Expire(key, 60 * 4);
|
|
|
+ RedisHelper.Expire(key, smsTTL);
|
|
|
Dictionary<string, object> da = new Dictionary<string, object>() { { "msgid", msgidstr }, { "repeat", false } };
|
|
|
return builder.Data(da).build();
|
|
|
}
|