Exemple #1
0
        public static ServiceStatus Login(AppUserCredentail credentail)
        {
            // Serialize the students to json
            var serializer        = new JavaScriptSerializer();
            var jsonRequestString = serializer.Serialize(credentail);
            var bytes             = Encoding.UTF8.GetBytes(jsonRequestString);

            // Initiate the HttpWebRequest with session support with CookiedFactory
            var request = CookiedRequestFactory.CreateHttpWebRequest(LoginUrl);

            request.Method      = "POST";
            request.ContentType = "application/json";
            request.Accept      = "application/json";

            // Send the json data to the Rest service
            var postStream = request.GetRequestStream();

            postStream.Write(bytes, 0, bytes.Length);
            postStream.Close();

            // Get the login status from the service
            var response           = (HttpWebResponse)request.GetResponse();
            var reader             = new StreamReader(response.GetResponseStream());
            var jsonResponseString = reader.ReadToEnd();

            reader.Close();
            response.Close();

            // Deserialize the json and return the result
            return(serializer.Deserialize <ServiceStatus>(jsonResponseString));
        }
Exemple #2
0
        public MainWindowVM()
        {
            // Initialize the properties
            UserCredentail = new AppUserCredentail();

            LoginVisibility = Visibility.Visible;
            WireCommands();
        }
Exemple #3
0
        public ServiceStatus Login(AppUserCredentail credentail)
        {
            // Initiate status as fail to login.
            var status = new ServiceStatus()
            {
                Success = false, Message = "Wrong user name and/or password"
            };

            // For simplicity, this example application has only one user.
            if ((credentail.UserName == "user") && (credentail.Password == "password"))
            {
                status.Success = true;
                status.Message = "Login success";
            }

            // Keep the login status in the HttpSessionState
            context.Session["USERLOGGEDIN"] = status.Success? "YES": null;

            return(status);
        }