예제 #1
0
파일: UserService.cs 프로젝트: kamlys/Game
 public bool Update(UserDto user)
 {
     try
     {
         foreach (var item in _user.GetAll().Where(i => i.ID == user.ID))
         {
             if (_user.GetAll().Any(i => i.Login == user.Login || i.Email == user.Email))
             {
                 return false;
             }
             else
             {
                 item.Login = user.Login;
                 item.Password = _user.GetAll().First(i => i.Login == user.Login).Password;
                 item.Email = user.Email;
                 item.Last_Log = user.Last_Log;
                 item.Registration_Date = user.Registration_Date;
                 item.Last_Update = user.Last_Update;
             }
         }
         _unitOfWork.Commit();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
예제 #2
0
파일: UserService.cs 프로젝트: kamlys/Game
        public int RecoveryPass(UserDto user)
        {
            int uID = _user.GetAll().First(i => i.Email == user.Email).ID;

            if (_recoveryCodes.GetAll().Any(i => i.User_ID == uID && i.Code == user.Code))
            {
                int liveCode = _recoveryCodes.GetAll().First(i => i.User_ID == uID && i.Code == user.Code).LiveTime.Subtract(DateTime.Now).Minutes;

                if (liveCode>=0 && liveCode<=10)
                {
                    _user.Get(uID).Password = _hassPass.GeneratePassword(user.Password);
                    _recoveryCodes.Delete(_recoveryCodes.GetAll().First(i => i.Code == user.Code));
                    _unitOfWork.Commit();

                    return 1; //Wszystko ok
                }
                else
                {
                    _recoveryCodes.Delete(_recoveryCodes.GetAll().First(i => i.Code == user.Code));
                    _unitOfWork.Commit();
                    return 3; // Kod się przedawnił.
                }
            }
            else
            {
                return 2; //Kod niepoprawny;
            }
        }
예제 #3
0
파일: UserService.cs 프로젝트: kamlys/Game
        public int[] RegisterUser(UserDto user)
        {
            bool success = false;
            if (!_user.GetAll().Any(u => u.Login == user.Login) && !_user.GetAll().Any(u => u.Email == user.Email))
            {
                _user.Add(new Users
                {
                    Login = user.Login,
                    Email = user.Email,
                    Password = _hassPass.GeneratePassword(user.Password),
                    Registration_Date = DateTime.Now,
                    Last_Log = DateTime.Now,
                    Last_Update = DateTime.Now
                });
            }

            List<int> val = new List<int>();

            if (!_user.GetAll().Any(u => u.Login == user.Login) && !_user.GetAll().Any(u => u.Email == user.Email))
            {
                val.Add(0);
            }
            if (_user.GetAll().Any(u => u.Login == user.Login))
            {
                val.Add(1);
            }
            if (_user.GetAll().Any(u => u.Email == user.Email))
            {
                val.Add(2);
            }

            if (_unitOfWork.Commit() > 0)
            {
                success = true;
            }

            if (success)
            {
                int uID = _user.GetAll().First(u => u.Login == user.Login).ID;

                _map.Add(new Maps
                {
                    User_ID = uID,
                    Width = 10,
                    Height = 10
                });

                _dolar.Add(new Dolars
                {
                    User_ID = uID,
                    Value = 100000
                });

                _tutorial.Add(new Tutorials
                {
                    User_ID = uID,
                    allDiv = false,
                    cookies = false,
                    casinoDiv = false,
                    homeDiv = false,
                    marketDiv = false,
                    messageDiv = false,
                    officeDiv = false,
                    rankDiv = false,
                    setDiv = false
                });

                _unitOfWork.Commit();
            }
            if (user.Password.Length < 5 || user.Password.ToCharArray().All(char.IsDigit))
            {
                val.Add(3);
            }

            return val.ToArray();
        }
예제 #4
0
파일: UserService.cs 프로젝트: kamlys/Game
        public int LoginUser(UserDto userLogin)
        {
            if (_user.GetAll().Any(u => u.Login == userLogin.Login))
            {
                int uID = _user.GetAll().First(i => i.Login == userLogin.Login).ID;

                if (_ban.GetAll().Any(i => i.User_ID == uID && i.Finish_Date > DateTime.Now))
                {
                    return 4;
                }
                else if (_ban.GetAll().Any(i => i.User_ID == uID))
                {
                    int id = _ban.GetAll().First(i => i.User_ID == uID).ID;

                    _ban.Delete(_ban.Get(id));
                    _unitOfWork.Commit();
                }

                var user = _user.GetAll().First(u => u.Login == userLogin.Login);

                if (_hassPass.ValidationPassword(userLogin.Password, user.Password))
                {
                    user.Last_Log = DateTime.Now;
                    _unitOfWork.Commit();
                    return 1;
                }
                else
                {
                    return 2;
                }
            }
            return 3;
        }
예제 #5
0
파일: UserService.cs 프로젝트: kamlys/Game
        public UserDto Profil(string User)
        {
            UserDto userDto = new UserDto();

            foreach (var item in _user.GetAll().Where(i => i.Login == User))
            {
                userDto.Login = item.Login;
                userDto.Email = item.Email;
                userDto.Registration_Date = (DateTime)item.Registration_Date;
                userDto.Last_Log = (DateTime)item.Last_Log;
            }
            return userDto;
        }
예제 #6
0
파일: UserService.cs 프로젝트: kamlys/Game
        public bool ChangeEmail(UserDto user, string User)
        {
            bool temp = false;
            foreach (var item in _user.GetAll())
            {
                if (item.Email == user.Email)
                {
                    temp = true;
                }
            }

            if (!temp)
            {
                _user.GetAll().First(i => i.Login == User).Email = user.Email;
                _unitOfWork.Commit();
                return true;
            }
            return false;
        }
예제 #7
0
파일: UserService.cs 프로젝트: kamlys/Game
 public bool ChangePass(UserDto user, string User)
 {
     foreach (var item in _user.GetAll().Where(i => i.Login == User))
     {
         if (_hassPass.ValidationPassword(user.OldPassword, item.Password))
         {
             _user.GetAll().First(i => i.Login == User).Password = _hassPass.GeneratePassword(user.Password);
             _unitOfWork.Commit();
             return true;
         }
         else
         {
             return false;
         }
     }
     return false;
 }
예제 #8
0
        public ActionResult AddUser(UserViewModel userModel)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            UserDto _userDto = new UserDto();

            _userDto.Login = userModel.viewModel.User_Login;
            _userDto.Password = userModel.viewModel.Password;
            _userDto.Email = userModel.viewModel.Email;
            //_userDto.Last_Log = userModel.viewModel.LastLog;
            //_userDto.Registration_Date = userModel.viewModel.RegistrationDate;
            //_userDto.Last_Update = userModel.viewModel.LastUpdate;

            if (_userService.Add(_userDto))
            {
                errors.Add("Dodano użytkownika.");
            }
            else
            {
                errors.Add("Błąd. Spróbuj ponownie.");
            }
            Session["val"] = errors.ToArray<string>();

            return RedirectToAction("Admin");
        }
예제 #9
0
파일: UserService.cs 프로젝트: kamlys/Game
        public bool Add(UserDto user)
        {
            if (!_user.GetAll().Any(i => i.Login == user.Login || i.Email == user.Email))
            {
                try
                {
                    _user.Add(new Users
                    {
                        Login = user.Login,
                        Password = _hassPass.GeneratePassword(user.Password),
                        Email = user.Email,
                        Last_Log = DateTime.Now,
                        Last_Update = DateTime.Now,
                        Registration_Date = DateTime.Now
                    });

                    _unitOfWork.Commit();

                    int uID = _user.GetAll().First(u => u.Login == user.Login).ID;

                    _map.Add(new Maps
                    {
                        User_ID = uID,
                        Width = 10,
                        Height = 10
                    });

                    _dolar.Add(new Dolars
                    {
                        User_ID = uID,
                        Value = 100000
                    });

                    _tutorial.Add(new Tutorials
                    {
                        User_ID = uID,
                        allDiv = false,
                        cookies = false,
                        casinoDiv = false,
                        homeDiv = false,
                        marketDiv = false,
                        messageDiv = false,
                        officeDiv = false,
                        rankDiv = false,
                        setDiv = false
                    });

                    _unitOfWork.Commit();

                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
            return false;
        }
예제 #10
0
        public ActionResult ChangeEmail(ProfileViewModel email)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }
            UserDto user = new UserDto();

            user.Email = email.EmailAddress;

            if (_userService.ChangeEmail(user, User.Identity.Name))
            {
                errors.Add("Email został zmieniony.");
                Session["val"] = errors.ToArray<string>();
                return RedirectToAction("Profil", new
                {
                    User = User.Identity.Name
                });
            }
            else
            {
                errors.Add("Błąd. Email nie został zmieniony.");
                Session["val"] = errors.ToArray<string>();
                return RedirectToAction("Profil", new
                {
                    User = User.Identity.Name
                });
            }
        }
예제 #11
0
        public ActionResult Register(RegisterViewModel register)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            UserDto user = new UserDto();

            user.Login = register.Login;
            user.Email = register.Email;
            user.Password = register.Password;

            foreach (var item in _userService.RegisterUser(user))
            {
                if (item == 0)
                {
                    FormsAuthentication.SetAuthCookie(user.Login, true);
                    return RedirectToAction("Index", "Home");
                }
                else if (item == 1)
                {
                    errors.Add("Login już istnieje");
                }
                else if (item == 2)
                {
                    errors.Add("Email już istnieje");
                }
                else if (item == 3)
                {
                    errors.Add("Hasło musi zawierać minimum 5 znaków, w tym jedną cyfrę.");
                }

            }

            Session["val"] = errors.ToArray<string>();

            return View();
        }
예제 #12
0
        public ActionResult RecoveryPass(RegisterViewModel user)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            UserDto userDto = new UserDto();
            userDto.Password = user.Password;
            userDto.Code = user.RecoveryCode;
            userDto.Email = user.Email;

            int result = _userService.RecoveryPass(userDto);

            if (result == 1)
            {
                errors.Clear();
                errors.Add("Hasło zostało zmienione.");
                Session["val"] = errors.ToArray<string>();
                return RedirectToAction("Login");
            }
            else if (result == 2)
            {
                errors.Clear();
                errors.Add("Niepoprawny kod.");
            }
            else if (result == 3)
            {
                errors.Clear();
                errors.Add("Kod stracił ważność.");
            }
            Session["val"] = errors.ToArray<string>();
            return RedirectToAction("RecoveryPassword");
        }
예제 #13
0
        public ActionResult Login(LoginViewModel modelLogin, string returnUrl)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }
            UserDto user = new UserDto();

            user.Login = modelLogin.Login;
            user.Password = modelLogin.Password;

            if (_userService.LoginUser(user) == 1)
            {
                FormsAuthentication.SetAuthCookie(modelLogin.Login, true);

                return RedirectToAction("Index", "Home");
            }
            else if (_userService.LoginUser(user) == 2 || _userService.LoginUser(user) == 3)
            {
                errors.Add("Login bądź hasło niepoprawne.");
            }
            else if (_userService.LoginUser(user) == 4)
            {
                return View("~/Views/Error/_Blocked.cshtml");
            }

            Session["val"] = errors.ToArray<string>();

            return View(modelLogin);
        }
예제 #14
0
        public ActionResult ChangePass(ProfileViewModel pass)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            UserDto user = new UserDto();

            user.OldPassword = pass.OldPassword;
            user.Password = pass.Password;

            if (_userService.ChangePass(user, User.Identity.Name))
            {
                errors.Add("Hasło zostało zmienione");
                Session["val"] = errors.ToArray<string>();
                return RedirectToAction("Profil", new
                {
                    User = User.Identity.Name
                });
            }
            else
            {
                errors.Add("Błąd. Hasło nie zostało zmienione.");
                Session["val"] = errors.ToArray<string>();
                return RedirectToAction("Profil", new
                {
                    User = User.Identity.Name
                });
            }
        }