Пример #1
0
        public ActionResult LogInUser()
        {
            object respond;
            string pass     = (string)Request.Params["password"];
            string username = (string)Request.Params["username"];

            if (string.IsNullOrEmpty(pass) || string.IsNullOrEmpty(username))
            {
                respond = new
                {
                    tittle       = "Login user",
                    message      = "Login user",
                    option       = "Login",
                    errorMessage = "Please complete all fields."
                };

                return(View("401", respond, "login"));
            }

            Model.Repository.UserRepository userRepository = new Model.Repository.UserRepository();
            Model.Entities.User             user           = userRepository.Login(username, pass);

            if (!string.IsNullOrEmpty(user.username))
            {
                string tokenGenerated = Session.GenerateToken(user.username, user.password, secretWord);
                authorizationUser = new AuthorizationUser(user.username, user.password, secretWord);

                respond = new {
                    tittle     = "Pick Url",
                    token      = tokenGenerated,
                    idUser     = user.id,
                    option     = "Sign Out",
                    message    = "Welcome to Pick Url.",
                    userLogged = user.firstName
                };

                return(View("200", respond, "index"));
            }
            else
            {
                respond = new {
                    tittle       = "Login user",
                    message      = "Login user",
                    option       = "Login",
                    errorMessage = "Passwod or Username incorrect."
                };

                return(View("401", respond, "login"));
            }
        }
Пример #2
0
        public ActionResult RegisterUser()
        {
            object respond;

            if (Request.Params.Count < 6)
            {
                respond = new
                {
                    tittle       = "Pick Url",
                    message      = "Welcome to Pick Url",
                    errorMessage = "Please complete all fields."
                };

                return(View("401", respond, "register"));
            }

            string password       = (string)Request.Params["password"];
            string confirpassword = (string)Request.Params["confPassword"];

            if (!password.Equals(confirpassword))
            {
                respond = new
                {
                    tittle       = "Pick Url",
                    message      = "Welcome to Pick Url",
                    errorMessage = "Password and confirm password must be the same.."
                };

                return(View("401", respond, "register"));
            }


            Model.Entities.User             user           = new Model.Entities.User();
            Model.Repository.UserRepository userRepository = new Model.Repository.UserRepository();

            user.firstName   = (string)Request.Params["firstName"];
            user.lastName    = (string)Request.Params["lastName"];
            user.username    = (string)Request.Params["username"];
            user.password    = (string)Request.Params["password"];
            user.nationality = (string)Request.Params["nationality"];


            if (userRepository.HasUser(user.username))
            {
                respond = new
                {
                    tittle       = "Pick Url",
                    message      = "Welcome to Pick Url",
                    errorMessage = "This username already exists.."
                };

                return(View("400", respond, "register"));
            }

            userRepository.AddUser(user);

            respond = new
            {
                tittle     = "Pick Url",
                option     = "Sign Out",
                message    = "Welcome to Pick Url.",
                userLogged = user.firstName
            };

            return(View("200", respond, "index"));
        }