Beispiel #1
0
        public IUnitOfWorkResult Add(Client client)
        {
            string _salt = GenerateSalt(32);
            client.Salt = _salt;
            client.Password = CreatePasswordHash(client.Password, _salt);

            var repo = RepoGeneric;
            repo.Add<Client>(client);
            var res = repo.UnitOfWork.SaveChanges();
            return res;
        }
Beispiel #2
0
        public IUnitOfWorkResult EditUser(Client client)
        {
            var repo = RepoGeneric;
            Client editedClient = RepoGeneric.FindOne<Client>(c => c.ClientId == client.ClientId);

            editedClient.FirstName = client.FirstName;
            editedClient.LastName = client.LastName;
            editedClient.Email = client.Email;

            if (!String.IsNullOrEmpty(client.Password))
            {
                string _salt = GenerateSalt(32);
                editedClient.Salt = _salt;
                editedClient.Password = CreatePasswordHash(client.Password, _salt);
            }

            var res = repo.UnitOfWork.SaveChanges();

            return res;
        }
Beispiel #3
0
        public PartialViewResult Register(RegisterModel model)
        {
            if (!string.IsNullOrEmpty(model.Phone) && !Manager.CheckIfPhoneUniq(model.Phone))
                ModelState.AddModelError("Phone", "Taki telefon został już zarejestrowany");

            if (ModelState.IsValid)
            {
                Client newUser = new Client();
                newUser.FirstName = model.Name;
                newUser.Phone = model.Phone;
                newUser.CreationDate = DateTime.Now;
                newUser.Password = model.Password;
                newUser.ActivateCode = Manager.GenerateSmsCode();
                newUser.IsActive = false;
                newUser.SmsSentCount = 1;

                var res = Manager.Add(newUser);

                if (!res.IsError)
                {

                    //TODO wyslac SMS

                    return PartialView("Partial/_registerSuccessPartial", newUser.ClientId);
                }
            }

            return PartialView("Partial/_registerPartial", model);
        }
Beispiel #4
0
        public IUnitOfWorkResult AddByCode(string phone, string name)
        {
            var repo = RepoGeneric;
            var client = repo.FindOne<Client>(c => c.Phone.Equals(phone));

            if (client == null)
            {
                client = new Client();

                client.Phone = phone;
                client.FirstName = name;
                client.CreationDate = DateTime.Now;

                client.IsActive = false;

                string _salt = GenerateSalt(32);
                client.Salt = _salt;
                client.Password = CreatePasswordHash(GenerateSmsCode(10).ToString(), _salt);

                repo.Add<Client>(client);
            }
            else
            {
                if (client.SmsSentCount.GetValueOrDefault() >= 3)
                    return CreateResultError("SMS_LIMIT");
            }

            client.ActivateCode = GenerateSmsCode();
            client.SmsSentCount += 1;

            //TODO wysłac kod

            var res = repo.UnitOfWork.SaveChanges();
            return res;
        }
Beispiel #5
0
        private void LogInUser(Client client)
        {
            FormsAuthentication.SetAuthCookie(client.Phone, true);

            UserData userData = new UserData
            {
                Phone = client.Phone,
                ID = client.ClientId,
                FullName = client.FullName
            };

            Manager.UpdateLastLoginDate(client.ClientId);

            //Nadpisuje cookie dla przechowywania dodatkowych informacji
            Response.SetAuthCookie(client.Phone, true, userData);
        }