Example #1
0
        public BaseUser SignUp(string login, string email, string password, bool saveChanges)
        {
            if (string.IsNullOrWhiteSpace(email) || string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException();
            }

            Guid hash, salt;

            SecurityService.GeneratePasswordHash(password, out hash, out salt);

            var federation = DataService.PerThread.GroupSet.SingleOrDefault(x => x.Id == ConstHelper.RootGroupId);

            if (federation == null)
            {
                throw new BusinessLogicException("Не создана группа Федерация");
            }

            var encryptedEmail = CryptographyService.EncryptEmail(email);
            var emailUser      = DataService.PerThread.BaseUserSet.OfType <User>().SingleOrDefault(x => x.EncryptedEmail == encryptedEmail);

            if (emailUser != null)
            {
                throw new BusinessLogicException("Указанная почта уже используется");
            }

            var user = new User // TODO: Регистрация админов должна идти отдельной функцией
            {
                Login                       = login,
                Email                       = email,
                Password                    = hash,
                Salt                        = salt,
                IsVerified                  = false,
                RegistrationDate            = DateTime.Now,
                LiveJournalSindication      = true,
                LiveJournalSindicateAsDraft = false,
                LastActivity                = DateTime.Now
            };

            user.SubscriptionSettings = new SubscriptionSettings {
                SubscriptionEmail = email
            };

            var gm = new GroupMember
            {
                EntryDate = DateTime.Now,
                GroupId   = federation.Id,
                State     = (byte)GroupMemberState.Approved,
                UserId    = user.Id
            };

            DataService.PerThread.GroupMemberSet.AddObject(gm);
            SubscriptionService.SubscribeToGroup(federation, user);
            VotingService.AnalizeGroupMemberBulletins(gm.Id);

            return(user);
        }
Example #2
0
        public User EmailUserValidation(string email, string password)
        {
            var encryptedEmail = CryptographyService.EncryptEmail(email);
            var user           = DataService.PerThread.BaseUserSet.OfType <User>().FirstOrDefault(x => x.EncryptedEmail == encryptedEmail);

            if (user == null)
            {
                return(null);
            }

            var passwordHash = CalcPasswordHash(password, user.Salt);

            return(passwordHash == user.Password ? user : null);
        }
Example #3
0
        public bool Authorize(string login, string password)
        {
            bool result = true;

            _login       = login;
            _md5Password = CryptographyService.EncryptPassword(password);

            try
            {
                GetBalance();
            }
            catch (Exception e)
            {
                result = false;
            }

            return(result);
        }