Beispiel #1
0
        public ActionResult Office365SignIn()
        {
            currentContext.HttpContext.Session.SetString("LoginType", "Login");
            string loginUrl = ADAuthUtils.GetLoginUrl();

            return(Redirect(loginUrl));
        }
        public IActionResult Office365([FromBody] Dictionary <string, string> code)
        {
            if (!string.IsNullOrWhiteSpace(code["code"]))
            {
                var accessTokenRes = ADAuthUtils.GetAccessToken(code["code"], code["callback"]);

                if (!accessTokenRes.status)
                {
                    //return BadRequest("Code is not valid.");
                    return(BadRequest(accessTokenRes.message));
                }
                var claimData = ADAuthUtils.GetClaimData(accessTokenRes.Data.Id_Token);

                ResponseModel <Office365Model> response = new ResponseModel <Office365Model>();
                response = _accountManager.OfficeLoginApi(claimData);
                if (response.status)
                {
                    var tokenData = JwtAuthentication.GenerateToken(response.Data.Email);
                    response.Data.Token        = tokenData.Data.Token;
                    response.Data.RefreshToken = tokenData.Data.RefreshToken;
                    response.Data.ExpiresIn    = tokenData.Data.ExpiresIn;
                    //response.Data.Token = JwtAuthentication.BuildToken(response.Data.Email,response.Data.GivenName);
                    return(Ok(response.Data));
                }
                else
                {
                    return(BadRequest(response.message));
                }
            }
            return(BadRequest("Error occurred. Please try again."));
        }
Beispiel #3
0
        // DELETE api/<controller>/5
        public IActionResult Delete(int id)
        {
            var LastUpdatedBy = ADAuthUtils.GetLoggedUserEmail(HttpContext);
            var result        = examManager.Delete(id, LastUpdatedBy);

            if (result.status)
            {
                return(Ok(result.message));
            }
            else
            {
                return(BadRequest(result.message));
            }
        }
Beispiel #4
0
        public IActionResult DeleteMultipleRecords([FromBody] List <int> Ids)
        {
            var LastUpdatedBy = ADAuthUtils.GetLoggedUserEmail(HttpContext);
            var result        = examsession.DeleteMultiple(Ids.ToArray(), LastUpdatedBy);

            if (result.status)
            {
                return(Json(new { isSuccess = true }));
            }
            else
            {
                return(Json(new { isSuccess = false }));
            }
        }
Beispiel #5
0
        public IActionResult Delete(int id)
        {
            var LastUpdatedBy = ADAuthUtils.GetLoggedUserEmail(HttpContext);
            var result        = examsession.Delete(id, LastUpdatedBy);

            if (result.status)
            {
                return(Json(new { isSuccess = true }));
            }
            else
            {
                return(Json(new { isSuccess = false }));
            }
        }
Beispiel #6
0
        public IActionResult UpdateStatusForMultipleRecords([FromBody] Technical.Models.UpdateMultiRecords records)
        {
            List <int> Ids           = records.Ids;
            int        statusId      = records.StatusId;
            var        LastUpdatedBy = ADAuthUtils.GetLoggedUserEmail(HttpContext);
            var        result        = examsession.UpdateExamStatusForMultiple(Ids.ToArray(), statusId, LastUpdatedBy);

            if (result)
            {
                return(Json(new { isSuccess = true }));
            }
            else
            {
                return(Json(new { isSuccess = false }));
            }
        }
Beispiel #7
0
        // PUT api/<controller>/5
        public IActionResult Update([FromBody] ExamModel model)
        {
            model.LastUpdatedBy = ADAuthUtils.GetLoggedUserEmail(HttpContext);
            model.LastUpdatedOn = DateTime.Now;
            var result = examManager.Update(model);

            if (result.status)
            {
                if (model.TestId > 0)
                {
                    examQuestionManager.Update(model.Questions, model.TestId);
                }
                return(Ok(result.message));
            }
            else
            {
                return(BadRequest(result.message));
            }
        }
 public IActionResult Office365SignUp(string code, string callbackurl)
 {
     if (!string.IsNullOrWhiteSpace(code))
     {
         var accessTokenRes = ADAuthUtils.GetAccessToken(code, callbackurl);
         if (!accessTokenRes.status)
         {
             return(BadRequest("Code is not valid."));
         }
         var claimData = ADAuthUtils.GetClaimData(accessTokenRes.Data.Id_Token);
         ResponseModel <Office365Model> response = new ResponseModel <Office365Model>();
         response = _accountManager.Office365SignUpApi(claimData);
         if (response.status)
         {
             return(Ok(response.Data));
         }
         else
         {
             return(BadRequest(response.message));
         }
     }
     return(BadRequest("Error occurred. Please try again."));
 }
Beispiel #9
0
        public ActionResult OnAuthComplete(string code)
        {
            //  HttpContext.Session.SetString(
            if (string.IsNullOrWhiteSpace(currentContext.HttpContext.Request.Query["code"]))
            {
                return(RedirectToLogin("Error occurred!"));
            }
            else
            {
                var callbackUrl    = ADAuthUtils.AppSettings.RedirectUri;
                var accessTokenRes = ADAuthUtils.GetAccessToken(currentContext.HttpContext.Request.Query["code"], callbackUrl);
                if (!accessTokenRes.status)
                {
                    return(RedirectToLogin(accessTokenRes.message));
                }
                var claimData = ADAuthUtils.GetClaimData(accessTokenRes.Data.Id_Token);
                if (Convert.ToString(currentContext.HttpContext.Session.GetString("LoginType")) == "Login")
                {
                    var result = _accountManager.Office365Login(claimData);
                    if (result.status)
                    {
                        // currentContext.HttpContext.Session.SetString("LoginType", null);

                        var claims = new List <Claim> {
                            new Claim(ClaimTypes.Name, claimData["email"]),
                            new Claim("FullName", claimData.ContainsKey("given_name")? claimData["given_name"]:claimData["name"])
                        };
                        var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                        var authProperties = new AuthenticationProperties {
                        };
                        currentContext.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties);

                        currentContext.HttpContext.Session.Remove("LoginType");
                        return(RedirectToAction("Index", "CreateSession"));
                    }
                    else
                    {
                        ViewBag.ErrorMessage = result.message;
                        return(View("Error"));
                    }
                }
                else if (Convert.ToString(currentContext.HttpContext.Session.GetString("LoginType")) == "SignUp")
                {
                    var result = _accountManager.Office365SignUp(claimData);
                    if (result.status)
                    {
                        // currentContext.HttpContext.Session.SetString("LoginType", null);
                        currentContext.HttpContext.Session.Remove("LoginType");
                        return(RedirectToAction("Index", "CreateSession"));
                    }
                    else
                    {
                        ViewBag.ErrorMessage = result.message;
                        return(View("Error"));
                    }
                }
                else if (Convert.ToString(currentContext.HttpContext.Session.GetString("LoginType")) == "View")
                {
                    var result = _accountManager.Office365Login(claimData);
                    if (result.status)
                    {
                        //currentContext.HttpContext.Session.SetString("LoginType", null);
                        currentContext.HttpContext.Session.Remove("LoginType");
                        var url = Convert.ToString(currentContext.HttpContext.Session.GetString("url"));
                        currentContext.HttpContext.Session.Remove("url");
                        //currentContext.HttpContext.Session.SetString("", null);
                        return(Redirect(url));
                    }
                    else
                    {
                        return(View("Error"));
                    }
                }
                else
                {
                    return(View("Error"));
                }
            }
        }
        public IActionResult Office365SignIn(string callbackUrl)
        {
            string officeUrl = ADAuthUtils.GetLoginUrl(callbackUrl);

            return(Ok(officeUrl));
        }
        public IActionResult SignUp(string url)
        {
            string officeUrl = ADAuthUtils.GetLoginUrl(url);

            return(Ok(officeUrl));
        }