Ejemplo n.º 1
0
        public bool Login(User details)
        {
            var allUsers = GetAll();
            var success  = allUsers.Any(x =>
                                        x.Email == details.Email &&
                                        StringCipherHelper.Decrypt(x.Password, "_UsrMgt") == details.Password);

            return(success);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public User GetById(long id)
        {
            var user = _userContext.Users.FirstOrDefault(x => x.Id == id);

            var password = user.Password;

            if (password != null)
            {
                user.Password = StringCipherHelper.Decrypt(password, "_UsrMgt");
            }

            return(user);
        }
Ejemplo n.º 3
0
        public IActionResult Register([FromBody] User user)
        {
            if (user == null)
            {
                return(BadRequest("Invalid data. Please check your input and try again."));
            }

            var password = user.Password;

            if (password == null)
            {
                return(BadRequest("Invalid password. Please try again."));
            }
            else
            {
                user.Password = StringCipherHelper.Encrypt(password, "_UsrMgt");
            }

            var success = _dataRepository.Add(user);

            if (!success)
            {
                return(BadRequest("An error occured. Please try again."));
            }

            return(CreatedAtRoute(
                       "get",
                       new { Id = user.Id },
                       new
            {
                user.Id,
                user.Name,
                user.Country,
                user.Surnames,
                user.Phone,
                user.Email,
                Password = StringCipherHelper.Decrypt(user.Password, "_UsrMgt"),
                user.PostCode
            }));
        }