Exemple #1
0
        public async Task <ResponseService <UserLoginModel> > Login(string email, string password)
        {
            try
            {
                _logger.LogInfo(Method.GetCurrentMethod().Name);
                User user = await _userRepositoty.GetByEmailAsync(email);

                if (user == null)
                {
                    return(new ResponseService <UserLoginModel>("User not exist"));
                }
                if (user.Password == HashMD5.HashStringMD5(password))
                {
                    JwtService     jwt       = new JwtService(_config);
                    UserLoginModel userLogin = _mapper.Map <User, UserLoginModel>(user);
                    userLogin.AccessToken  = jwt.GenerateSecurityToken(userLogin.Email, false);
                    userLogin.RefreshToken = jwt.GenerateSecurityToken(userLogin.Email, true);
                    return(new ResponseService <UserLoginModel>(userLogin));
                }
                return(new ResponseService <UserLoginModel>("Wrong email or password"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new ResponseService <UserLoginModel>(ex.Message));
            }
        }
Exemple #2
0
        public async Task <ResponseService <User> > Register(UserModel userModel)
        {
            try
            {
                _logger.LogInfo(Method.GetCurrentMethod().Name);
                User userExist = await _userRepositoty.GetByEmailAsync(userModel.Email);

                if (userExist != null)
                {
                    return(new ResponseService <User>("This mail is exist in system!"));
                }

                User user = _mapper.Map <UserModel, User>(userModel);
                user.Password  = HashMD5.HashStringMD5(user.Password);
                user.CreatedAt = DateTime.Now;
                user.UpdatedAt = DateTime.Now;
                user.Active    = true;
                var userInfo = await _userRepositoty.AddAsync(user);

                Profile profile = new Profile();
                profile.Status    = Constants.DEFAULT_STATUS_PROFILE;
                profile.UserId    = userInfo.Id;
                profile.CreatedAt = DateTime.Now;
                profile.UpdatedAt = DateTime.Now;
                profile.Active    = true;
                await _profileRepository.AddAsync(profile);

                return(new ResponseService <User>(user));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new ResponseService <User>(ex.Message));
            }
        }
Exemple #3
0
 /// <summary>
 /// Checks if we are in internal
 /// </summary>
 public static bool IsInternal()
 {
     if (Assembly.GetAssembly(MethodBase.GetCurrentMethod().DeclaringType).GetType("MetaInternal", false, true) != null)
     {
         return(true);
     }
     return(false);
 }