Ejemplo n.º 1
0
        public IActionResult Login([FromBody] CenterDataRequest center)
        {
            //string URL = string.Format("http://10./api/Shared/DownloadLogo/{0}", centerid);
            using (var client = new WebClient())
            {
                try
                {
                    //Create Appoint To Onsiteoy
                    var jsonPreSheet = Newtonsoft.Json.JsonConvert.SerializeObject(center);

                    var dataByte = System.Text.Encoding.UTF8.GetBytes(jsonPreSheet);

                    client.Headers[HttpRequestHeader.ContentType] = "application/json";

                    //dataByte = client.UploadData("http://localhost/localdb/api/shared/createtestregistration", "POST", dataByte);
                    dataByte = client.UploadData(this.svconfig.admindbip + "/api/Shared/LoginToLocalDB/", "POST", dataByte);

                    //string URL = string.Format(this.svconfig.admindbip + "/api/Shared/DownloadLogo/{0}", centerid);
                    //var dataByte = client.DownloadData(URL);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            return(RedirectToAction(""));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    _logger.LogInformation(1, "User logged in.");
                    //return RedirectToLocal(returnUrl);
                    CenterDataRequest center = new CenterDataRequest
                    {
                        _id        = model.CenterId,
                        LatestUser = model.Email,
                        LatestPass = model.Password,
                    };

                    var data = _repoRegis.GetCenterData(center._id);
                    center.SiteId = data.SiteId;
                    if (data.CertDatas != null)
                    {
                        center.CertDatas = new List <CertData>();
                        foreach (var item in data.CertDatas)
                        {
                            center.CertDatas.Add(new CertData
                            {
                                UserCode = item.UserCode,
                                CertNo   = item.CertNo,
                                CertYear = item.CertYear,
                            });
                        }
                    }

                    center.NameEn         = data.NameEN;
                    center.NameTh         = data.NameTH;
                    center.UpdateDateTime = DateTime.Now;
                    var site = _repoRegis.GetSiteData(data.SiteId);
                    center.SiteName            = site.Name;
                    center.IsAutoSyncResult    = site.IsAutoSyncResult;
                    center.IsAutoSyncScore     = site.IsAutoSyncScore;
                    center.IsShowAnswer        = site.IsDisplayAnswer;
                    HomeController._centerdata = center;
                    return(RedirectToAction(nameof(HomeController.Index), "Home"));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning(2, "User account locked out.");
                    return(View("Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(View(model));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }