コード例 #1
0
 //constructor
 public BaseUserService()
 {
     _baseU = new BaseUserDto()
     {
         UserId   = "U01",
         UserName = "******",
         DeptId   = "D01",
         DeptName = "D01 name",
         Locale   = _Fun.Config.DefaultLocale,
         //FrontDtFormat = _Fun.Config.FrontDtFormat,
         //HourDiff = 0,
     };
 }
コード例 #2
0
        public async Task <ActionResult <UserCabinetDto> > UpdateUserProfile(BaseUserDto userDto)
        {
            User user = await _userManager.FindByEmailFromClaimsPrincipals(HttpContext.User);

            _mapper.Map <BaseUserDto, User>(userDto, user);

            IdentityResult result = await _userManager.UpdateAsync(user);

            if (!result.Succeeded)
            {
                return(BadRequest(new ApiResponse(400)));
            }

            return(Ok(_mapper.Map <User, UserCabinetDto>(user)));
        }
コード例 #3
0
        public async Task <IActionResult> Login(BaseUserDto model)
        {
            var user = await _userService.GetUserByLogin(model);

            if (user == null)
            {
                return(Ok(new LoginResultModel
                {
                    Success = false,
                    Message = Constants.Users.LoginAccountFail
                }));
            }

            var tokenString = _jwtManager.GenerateToken();

            return(Ok(new LoginResultModel
            {
                Success = true,
                Message = Constants.Users.LoginAccountSuccess,
                Token = tokenString
            }));
        }
コード例 #4
0
 public async Task <UserDto> GetUserByLogin(BaseUserDto model) => _mapper.Map <UserDto>(await _userRepository.Get(x => x.Email == model.Email && x.Password == model.Password));
コード例 #5
0
        public ActionResult Login(LoginVo vo)
        {
            //reset msg
            vo.AccountMsg = "";
            vo.PwdMsg     = "";

            #region check account & password
            if (string.IsNullOrEmpty(vo.Account))
            {
                vo.AccountMsg = "field is required.";
                goto lab_exit;
            }
            if (string.IsNullOrEmpty(vo.Pwd))
            {
                vo.PwdMsg = "field is required.";
                goto lab_exit;
            }

            //check password
            var sql = @"
select u.Id as UserId, u.Name as UserName, u.Pwd,
    u.DeptId, d.Name as DeptName
from dbo.[User] u
join dbo.[Dept] d on u.DeptId=d.Id
where u.Account=@Account
";
            var row = _Db.GetJson(sql, new List <object>()
            {
                "Account", vo.Account
            });
            //if (row == null || row["Pwd"].ToString() != _Str.Md5(vo.Pwd))
            if (row == null || row["Pwd"].ToString() != vo.Pwd)
            {
                vo.AccountMsg = "input wrong.";
                goto lab_exit;
            }
            #endregion

            #region set base user info
            var userId = row["UserId"].ToString();
            //var authType = AuthTypeEnum.Ctrl;
            var authList = _Prog.GetAuthList(vo.Account);
            var userInfo = new BaseUserDto()
            {
                UserId       = userId,
                UserName     = row["UserName"].ToString(),
                DeptId       = row["DeptId"].ToString(),
                DeptName     = row["DeptName"].ToString(),
                Locale       = _Fun.Config.DefaultLocale,
                ProgAuthStrs = _Prog.GetAuthStrs(authList),
                IsLogin      = true,
            };
            #endregion

            //set session of base user info
            var session = _Web.GetSession();
            session.Set(_Fun.BaseUser, userInfo);   //extension method

            //set locale
            //_Locale.SetCulture(locale);

            //redirect if need
            var url = string.IsNullOrEmpty(vo.FromUrl) ? "/Home/Index" : vo.FromUrl;
            return(Redirect(url));

lab_exit:
            return(View(vo));
        }