Пример #1
0
        public LoginRespnse validateUser(Users users)
        {
            objResponse  Response = new objResponse();
            LoginRespnse results  = new LoginRespnse();

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://zmetricsapi.cruzata.com/auth/login");

                    //HTTP POST
                    var postTask = client.PostAsJsonAsync <Users>("login", users);
                    postTask.Wait();

                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsAsync <LoginRespnse>();
                        readTask.Wait();

                        results = readTask.Result;
                    }
                }
            }
            catch (Exception ex)
            {
                results.header.ErrorMessage = ex.Message.ToString();
                BAL.Common.LogManager.LogError("validate User", 1, Convert.ToString(ex.Source), Convert.ToString(ex.Message), Convert.ToString(ex.StackTrace));
            }

            return(results);
        }
Пример #2
0
        public ActionResult Login(string username, string password)
        {
            LoginRespnse Response = new LoginRespnse();
            Users        users    = new Users();

            try
            {
                users.Email    = username;
                users.Password = password;

                Response = objUserManager.validateUser(users);

                if (Response.header.ErrorCode == 200)
                {
                    FormsAuthentication.SetAuthCookie(Response.response.Email, false);
                    SessionHelper session = new SessionHelper();
                    session.UserSession = new UserSession()
                    {
                        UserId   = Response.response.UserId,
                        Username = Response.response.Email,
                        FullName = Response.response.FullName
                    };

                    return(RedirectToRoute("home"));
                }
                else
                {
                    ViewBag.Error_Msg = Response.header.ErrorMessage;
                    return(View());
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error_Msg = ex.Message.ToString();
                BAL.Common.LogManager.LogError("Login Post Method", 1, Convert.ToString(ex.Source), Convert.ToString(ex.Message), Convert.ToString(ex.StackTrace));
                return(View());
            }
        }