예제 #1
0
        public async Task <ActionResult> Login(string inputUsername, string inputPassword)
        {
            if (Sessions.isAuthenticated(Request, Session))
            {
                return(RedirectToAction("Index", "Fans", new { area = "Fans", userId = Session["id"] }));
            }
            PostLoginUserForm form = new PostLoginUserForm();

            form.Username = inputUsername;
            form.Password = inputPassword;

            string response = await clsLoginRequests.PostLoginUserForm(form);

            System.Diagnostics.Debug.WriteLine(response);

            string ParsedMessage = ErrorParser.parse(response);

            //Hubo error
            if (!ParsedMessage.Equals(""))
            {
                ViewBag.Message = ParsedMessage;
                return(View("~/Views/Login/Index.cshtml"));
            }
            UserSession session = DataParser.parseUserForm(response);

            string token = Guid.NewGuid().ToString();

            Session["token"]    = token;
            Session["username"] = session.Username;
            Session["id"]       = session.Id;
            Session["rol"]      = session.Rol;
            Session["name"]     = session.Name;
            Session.Timeout     = 10;

            if (Sessions.isBand(session.Rol))
            {
                return(RedirectToAction("Index", "Bands", new { area = "Bands", userId = session.Id }));
            }
            else if (Sessions.isFan(session.Rol))
            {
                return(RedirectToAction("Index", "Fans", new { area = "Fans", userId = session.Id }));
            }
            else
            {
                return(HttpNotFound());
            }
        }
예제 #2
0
        public static async Task <string> PostLoginUserForm(PostLoginUserForm form)
        {
            // HTTP POST
            Serializer serializer  = new Serializer();
            string     RequestBody = serializer.Serialize(form);

            clsRequest          RequestObject = new clsRequest("-1", -1, RequestBody);
            HttpResponseMessage request       = await clsHttpClient.getClient().PostAsJsonAsync("users/login", RequestObject);

            if (request.IsSuccessStatusCode)
            {
                string response = request.Content.ReadAsStringAsync().Result;
                return(await Task.FromResult(response));
            }
            else
            {
                return(await Task.FromResult("Unexpected error ocurred"));
            }
        }