예제 #1
0
        public ServiceResponse <Core.Domain.Users> RegisterUser([FromBody] JObject jObject)
        {
            var response = new ServiceResponse <Core.Domain.Users>();

            try
            {
                var    user     = jObject.ToObject <Core.Domain.Users>();
                String salt     = _webHelper.RandomString(_webHelper.RandomStringSize) + "=";
                String password = _webHelper.ComputeHash(user.Password, salt, HashName.MD5);
                user.Password     = password;
                user.PasswordSalt = salt;
                var userId = _userService.RegisterUser(user);
                if (userId > 0)
                {
                    user.Id = userId;
                    _emailService.SendEmail("New Registration", "Welcome to Q2 " + user.FullName + ".<br/> This email is sent to confirm your registration with Q2. You can invite your friends and colleagues by sharing this code  <b>" + user.MyCode + "</b>. This code must be inserted in the designated field in the registration form. <br/>Again, thank you for joining Q2!<br/> Cheers! <br/>Q2", user.Email, null, null);
                }
                response.Model   = user;
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = GetErrorMessageDetail(ex);
            }
            return(response);
        }
예제 #2
0
        public Core.Domain.Users VerifyUser(string email, string password, string deviceNumber)
        {
            if (string.IsNullOrEmpty(email))
            {
                throw new ArgumentNullException(nameof(email));
            }
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException(nameof(password));
            }
            if (string.IsNullOrEmpty(deviceNumber))
            {
                throw new ArgumentNullException(nameof(deviceNumber));
            }
            var user = this._userRepository.Table.Where(u => u.Email.ToLower().Trim().Equals(email) && u.IsDeleted == false).FirstOrDefault();

            if (user != null)
            {
                if (user.IsActive == true)
                {
                    var salt = user.PasswordSalt;
                    password = _webHelper.ComputeHash(password, salt);
                    if (!user.Password.Equals(password))
                    {
                        throw new Exception("Oops! Invalid Username or Password");
                    }
                    else if (user.DeviceNumber.Equals(deviceNumber))
                    {
                        user.DeviceNumber = deviceNumber;
                        _userRepository.Update(user);
                    }
                }
                else
                {
                    throw new Exception("Oops! Your account is not activated. Please contact organization Administrator to activate your account.");
                }
            }
            else
            {
                throw new Exception("Oops! Invalid Username or Password.");
            }
            return(user);
        }