Exemple #1
0
        /// <summary>
        /// Saves the user in the database
        /// </summary>
        /// <param name="user">The form data the user send</param>
        public async Task Register(User user)
        {
            if (!await UserModelValid(user) || user.Password.Length < 8)
            {
                throw new UnprocessableException();
            }

            bool usernameOrEmailInUse = await _userDal.Exists(user.Username, user.Email);

            if (usernameOrEmailInUse)
            {
                throw new DuplicateNameException();
            }

            bool databaseContainsUsers = await _userDal.Any();

            var userDto = _mapper.Map <UserDto>(user);

            userDto.AccountRole = databaseContainsUsers ? AccountRole.User : AccountRole.SiteAdmin;
            userDto.Uuid        = Guid.NewGuid();

            var disabledUserDto = new DisabledUserDto
            {
                Reason   = DisableReason.EmailVerificationRequired,
                UserUuid = userDto.Uuid,
                Uuid     = Guid.NewGuid()
            };

            var activationDto = new ActivationDto
            {
                Code     = Guid.NewGuid().ToString(),
                UserUuid = userDto.Uuid,
                Uuid     = Guid.NewGuid()
            };

            await _disabledUserDal.Add(disabledUserDto);

            await _activationDal.Add(activationDto);

            var userRabbitMq = _mapper.Map <UserRabbitMqSensitiveInformation>(user);

            userRabbitMq.Uuid        = userDto.Uuid;
            userRabbitMq.AccountRole = databaseContainsUsers ? AccountRole.User : AccountRole.SiteAdmin;

            _publisher.Publish(userRabbitMq, RabbitMqRouting.AddUser, RabbitMqExchange.AuthenticationExchange);

            await _userDal.Add(userDto);

            SendActivationEmail(userDto, activationDto);
        }
Exemple #2
0
            public bool Login(string phone, string password)
            {
                var re = _userDal.Exists(phone, password);

                if (re)
                {
                    _smsSender.Send(phone, "您已成功登录系统");
                }

                return(re);
            }
Exemple #3
0
            public bool Login(string phone, string password)
            {
                bool re = _userDal.Exists(phone, password);

                if (re)
                {
                    ISmsSender smsSender = _smsSenderFactory.Create();
                    smsSender.Send(phone, "您已成功登录系统");
                }

                return(re);
            }
Exemple #4
0
        public RegisterState Register(User user)
        {
            if (!ValidateHelper.CheckUserName(user.Account))
            {
                return(RegisterState.InvalidAccount);
            }

            if (!ValidateHelper.CheckPassword(user.Password))
            {
                return(RegisterState.InvalidPassword);
            }

            if (!ValidateHelper.CheckEmail(user.Email))
            {
                return(RegisterState.InvalidEmail);
            }

            if (!ValidateHelper.CheckQQ(user.QQ))
            {
                return(RegisterState.InvalidQQ);
            }

            if (!ValidateHelper.CheckMobile(user.Mobile))
            {
                return(RegisterState.InvalidMobile);
            }

            string salt;

            user.Password = PasswordEncrypt.GetEncryptPassword(user.Password, out salt);
            user.Salt     = salt;
            user.Account  = user.Account.ToLower();

            if (_userDal.Exists(user.Account))
            {
                return(RegisterState.AccountExists);
            }

            if (!_userDal.Add(user))
            {
                return(RegisterState.Failed);
            }

            return(RegisterState.Successed);
        }
Exemple #5
0
 /// <summary>
 /// 是否存在该记录
 /// </summary>
 public bool Exists(int ID)
 {
     return(dal.Exists(ID));
 }
Exemple #6
0
 public IResult CheckUserExists(int id)
 {
     return(_userDal.Exists(u => u.Id == id) ? new SuccessResult() : new ErrorResult());
 }
Exemple #7
0
 public bool Exists(string email)
 {
     return(_userDal.Exists(email));
 }