コード例 #1
0
        public async Task <IHttpActionResult> ValidateUser(MSEADEW_BAL.BAL.Admin.Login iuc)
        {
            var result = new Dictionary <string, object>();

            try
            {
                if ((iuc.userName != null || iuc.userName != string.Empty) && (iuc.password != null || iuc.password == string.Empty))
                {
                    if (String.IsNullOrEmpty(iuc.userName) || String.IsNullOrEmpty(iuc.password))
                    {
                        throw new ArgumentNullException();
                    }
                    var tokenModel = new Dictionary <string, string>
                    {
                        { "grant_type", "password" },
                        { "username", iuc.userName },
                        { "password", iuc.password },
                    };
                    var response = await CallApiTask("api/authtoken", tokenModel);

                    if (!response.IsSuccessStatusCode)
                    {
                        var errors = await response.Content.ReadAsStringAsync();

                        throw new Exception(errors);
                    }

                    _myToken = response.Content.ReadAsAsync <Token>(new[] { new JsonMediaTypeFormatter() }).Result;
                    result.Add("Success", true);
                    result.Add("Data", _myToken);
                }
                else
                {
                    result.Add("Success", false);
                    result.Add("Data", "Username or Password cannot be Empty");
                }
                return(Ok(result));
            }
            catch (Exception E)
            {
                result.Add("Success", false);
                result.Add("Data", "Username or Password is Incorrect");
                return(Ok(result));
            }
        }
コード例 #2
0
        public async Task <IHttpActionResult> ValidateUser(Login common)
        {
            try
            {
                //  object[] parameters = null;
                //Logger.Debug("Validate User", common.UserName,common.Password);
                //Common.ValidateUser();
                string tokenEmail    = common.UserName;
                string tokenPassword = common.Password;
                if (String.IsNullOrEmpty(tokenEmail) || String.IsNullOrEmpty(tokenPassword))
                {
                    throw new ArgumentNullException();
                }

                var tokenModel = new Dictionary <string, string>
                {
                    { "grant_type", "password" },
                    { "username", tokenEmail },
                    { "password", tokenPassword },
                };
                var response = await CallApiTask("api/authtoken", tokenModel);

                if (!response.IsSuccessStatusCode)
                {
                    var errors = await response.Content.ReadAsStringAsync();

                    throw new Exception(errors);
                }
                _myToken = response.Content.ReadAsAsync <Token>(new[] { new JsonMediaTypeFormatter() }).Result;

                return(Ok(_myToken));
            }
            catch (Exception E)
            {
                Logger.Error(E, @"C:\DentalChartIcons\", "error.txt");
                return(Ok(E.Message.ToString()));
            }
        }