예제 #1
0
        /// <summary>
        /// 获取管理员信息
        /// </summary>
        /// <param name="requestDto"></param>
        /// <returns></returns>
        public async Task <MealAdminModel> GetMealAdmin(MealAdminLoginRequestDto requestDto)
        {
            var model = (MealAdminModel)null;

            var sql = @"select 
                            admin_guid,admin_name, password, hos_name, hospital_guid 
                        from t_meal_admin
                        where admin_name = @name and enable = 1";

            using (var conn = MySqlHelper.GetConnection())
            {
                model = await conn.QueryFirstOrDefaultAsync <MealAdminModel>(sql, new { name = requestDto.UserName });
            }

            if (model is null)
            {
                return(null);
            }

            var saltPwd = Common.Helper.CryptoHelper.AddSalt(model.AdminGuid, requestDto.Password);

            if (!saltPwd.Equals(model.Password))
            {
                return(null);
            }
            return(model);
        }
예제 #2
0
        public async Task <IActionResult> Login([FromBody] MealAdminLoginRequestDto request)
        {
            var adminBiz = new MealAdminBiz();

            var model = await adminBiz.GetMealAdmin(request);

            if (model is null)
            {
                return(Failed(ErrorCode.InvalidIdPassword, "账号或密码不正确"));
            }

            var token = CreateToken(model.AdminGuid, UserType.Admin, request.Days);

            return(Success(new MealAdminLoginResponseDto
            {
                HospitalName = model.HosName,
                HospitalId = model.HospitalGuid,
                UserName = model.AdminName,
                Token = token
            }));
        }