Exemple #1
0
        public Entity.BaseResponse <Entity.LoginResponse> Login(Entity.LoginRequest request)
        {
            Entity.BaseResponse <Entity.LoginResponse> response = new Entity.BaseResponse <Entity.LoginResponse>(true, "");
            try
            {
                Entity.ActionStatus loginResponse = _userService.Login(request);
                if (loginResponse != null && loginResponse.Success)
                {
                    response.IsSuccess = true;
                    response.Data      = GetApiResponse(loginResponse.Data);
                }
                else
                {
                    response.IsSuccess = false;
                    response.Message   = loginResponse.Message;
                }
            }

            catch (Exception ex)
            {
                base.LogException(ex);
                return(new Entity.BaseResponse <Entity.LoginResponse>(false, ex.Message));
            }
            return(response);
        }
Exemple #2
0
 public Entity.ActionStatus AdminLogin(Entity.LoginRequest request)
 {
     Entity.ActionStatus result = new ActionStatus(true);
     try
     {
         Model.AdminUser adminUser = _adminUserRepository.AdminLogin(request);
         if (adminUser == null)
         {
             result.Success = false;
             result.Message = "No User Found!";
         }
         else if (adminUser == null || !adminUser.Password.Equals(request.Password))
         {
             result.Success = false;
             result.Message = "Invalid credentials.";
         }
         else if (adminUser != null && (!adminUser.IsActive || adminUser.IsDeleted))
         {
             result.Success = false;
             result.Message = "Your account has been deactivated.";
         }
         else
         {
             result.Success = true;
             result.Data    = adminUser;
         }
     }
     catch (Exception ex)
     {
         result.Success = false;
         _logger.Error(Constants.ACTION_EXCEPTION, $"UserManager.Login {ex.Message}");
     }
     return(result);
 }
 public Entity.ActionStatus AdminLogin(Entity.LoginRequest request)
 {
     Entity.ActionStatus result = new ActionStatus(true);
     try
     {
         Model.AdminUser adminUser = _adminUserRepository.AdminLogin(request);
         if (adminUser == null)
         {
             result.Success = false;
             result.Message = "No User Found!";
         }
         else if (adminUser == null || !adminUser.Password.Equals(request.Password))
         {
             result.Success = false;
             result.Message = "Invalid credentials.";
         }
         else if (adminUser != null && (!adminUser.IsActive || adminUser.IsDeleted))
         {
             result.Success = false;
             result.Message = "Your account has been deactivated.";
         }
         else
         {
             result.Success = true;
             result.Data    = adminUser;
         }
     }
     catch (Exception ex)
     {
         result.Success = false;
         _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
     }
     return(result);
 }
        public Entity.ActionStatus Login(Entity.LoginRequest request)
        {
            Entity.ActionStatus result = new Entity.ActionStatus(true);
            try
            {
                IOT.DataResponse <IOT.LoginResult> loginResult = _iotConnectClient.Login.Login(new IOT.LoginModel()
                {
                    UserName = request.Username,
                    Password = request.Password
                }).Result;

                result.Success = loginResult.status;
                if (loginResult != null && loginResult.status)
                {
                    JwtSecurityTokenHandler hand = new JwtSecurityTokenHandler();
                    var tokenS    = hand.ReadJwtToken(loginResult.data.access_token);
                    var jsonValue = tokenS.Claims?.SingleOrDefault(p => p.Type == "user")?.Value;
                    Entity.UserDetail userDetail = Newtonsoft.Json.JsonConvert.DeserializeObject <Entity.UserDetail>(jsonValue);
                    var user = _userRepository.GetByUniqueId(r => r.Guid == Guid.Parse(userDetail.Id));

                    if (user == null)
                    {
                        return(new Entity.ActionStatus()
                        {
                            Success = false, Message = "User does not exist in Solution"
                        });
                    }
                    userDetail.FullName = user.FirstName.ToString() + " " + user.LastName.ToString();

                    result.Data = new Entity.LoginResponse
                    {
                        status        = loginResult.data.status,
                        data          = loginResult.data.data,
                        message       = loginResult.message,
                        token_type    = loginResult.data.token_type,
                        access_token  = loginResult.data.access_token,
                        refresh_token = loginResult.data.refresh_token,
                        expires_in    = loginResult.data.expires_in,
                        UserDetail    = userDetail
                    };
                }
                else
                {
                    result.Message = loginResult.message;
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex, $"UserManager.Login {ex.Message}");
                return(new Entity.ActionStatus(false, ex.Message));
            }
            return(result);
        }
Exemple #5
0
 public Model.AdminUser AdminLogin(Entity.LoginRequest request)
 {
     Model.AdminUser result = null;
     try
     {
         _logger.InfoLog(LogHandler.Constants.ACTION_ENTRY, null, "", "", this.GetType().Name, MethodBase.GetCurrentMethod().Name);
         result = _uow.DbContext.AdminUser.Where(x => x.Email.Equals(request.Username)).FirstOrDefault();
         _logger.InfoLog(LogHandler.Constants.ACTION_EXIT, null, "", "", this.GetType().Name, MethodBase.GetCurrentMethod().Name);
     }
     catch (Exception ex)
     {
         _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
     }
     return(result);
 }
Exemple #6
0
        public Model.AdminUser AdminLogin(Entity.LoginRequest request)
        {
            Model.AdminUser result = null;
            try
            {
                logger.Information(Constants.ACTION_ENTRY, "AdminUserRepository.Get");
                result = _uow.DbContext.AdminUser.Where(x => x.Email.Equals(request.Username)).FirstOrDefault();

                logger.Information(Constants.ACTION_EXIT, "AdminUserRepository.Get");
            }
            catch (Exception ex)
            {
                logger.Error(Constants.ACTION_EXCEPTION, ex);
            }
            return(result);
        }
Exemple #7
0
        public Entity.BaseResponse <Entity.LoginResponse> AdminLogin(Entity.LoginRequest request)
        {
            Entity.BaseResponse <Entity.LoginResponse> response = new Entity.BaseResponse <Entity.LoginResponse>(true);
            try
            {
                var loginResult = _adminUserService.AdminLogin(request);
                if (loginResult != null && loginResult.Success)
                {
                    var secretKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(System.Text.Encoding.UTF8.GetBytes(component.helper.SolutionConfiguration.Configuration.Token.SecurityKey));
                    List <System.Security.Claims.Claim> clm = new List <System.Security.Claims.Claim>();

                    var propertyInfoCompanyId = loginResult.Data.GetType().GetProperty("CompanyGuid");
                    var companyId             = propertyInfoCompanyId.GetValue(loginResult.Data, null);
                    var propertyInfoUserId    = loginResult.Data.GetType().GetProperty("Guid");
                    var currentUserId         = propertyInfoUserId.GetValue(loginResult.Data, null);

                    var firstName      = loginResult.Data.GetType().GetProperty("FirstName");
                    var fisrtNameValue = firstName.GetValue(loginResult.Data, null);

                    var lastName      = loginResult.Data.GetType().GetProperty("LastName");
                    var lastNameValue = lastName.GetValue(loginResult.Data, null);

                    string fullName = fisrtNameValue + " " + lastNameValue;

                    clm.Add(new System.Security.Claims.Claim("IOT_CONNECT", "AdminUser"));
                    clm.Add(new System.Security.Claims.Claim("CURRENT_USERID", currentUserId.ToString().ToUpper()));
                    var tokeOptions = new JwtSecurityToken(
                        issuer: component.helper.SolutionConfiguration.Configuration.Token.Issuer.ToLower(),
                        audience: component.helper.SolutionConfiguration.Configuration.Token.Audience.ToLower(),
                        claims: clm,
                        expires: DateTime.Now.AddMinutes(30),
                        signingCredentials: new Microsoft.IdentityModel.Tokens.SigningCredentials(secretKey, Microsoft.IdentityModel.Tokens.SecurityAlgorithms.HmacSha256)
                        );
                    response.IsSuccess = true;
                    response.Data      = new Entity.LoginResponse()
                    {
                        access_token = new JwtSecurityTokenHandler().WriteToken(tokeOptions),
                        expires_in   = DateTime.Now.AddMinutes(30).Ticks,
                        UserDetail   = new Entity.UserDetail
                        {
                            Id        = currentUserId.ToString().ToUpper(),
                            CompanyId = companyId.ToString().ToUpper(),
                            IsAdmin   = true,
                            FullName  = fullName
                        }
                    };
                }
                else
                {
                    response.IsSuccess = false;
                    response.Message   = loginResult.Message; //"Invalid Credentials.";
                    response.Data      = null;
                }
            }
            catch (Exception ex)
            {
                base.LogException(ex);
                return(new Entity.BaseResponse <Entity.LoginResponse>(false, ex.Message));
            }
            return(response);
        }