public IActionResult Register() { var RegisterModel = new RegisterModel(); var SecurityQuestionsList = new List <SecurityQuestion>(); string errorMessage = string.Empty; try { var apiCall = new ApiCallerSecurityQuestions(_apiUrl.SSAuth); SecurityQuestionsList = apiCall.GetAllSecurityQuestions(); var SecurityQuestionModelList = from secQuestion in SecurityQuestionsList select new QuestionsModel() { Id = secQuestion.SecurityQuestionId.ToString(), Name = secQuestion.Question }; SecurityQuestionModelList.ToList().Insert(0, new QuestionsModel() { Id = "", Name = "Please select a security question" }); ViewBag.QuestionList = SecurityQuestionModelList.ToList(); } catch (Exception ex) { errorMessage = ex.Message; } ViewBag.ErrorMessage = errorMessage; return(View(RegisterModel)); }
public IActionResult RegisterOrganization(RegisterModel model) { string errorMessage = string.Empty; var IndustryList = new List <Industry>(); try { var apiSecQCall = new ApiCallerSecurityQuestions(_apiUrl.SSAuth); var SecurityQuestionsList = apiSecQCall.GetAllSecurityQuestions(); var SecurityQuestionModelList = from secQuestion in SecurityQuestionsList select new QuestionsModel() { Id = secQuestion.SecurityQuestionId.ToString(), Name = secQuestion.Question }; SecurityQuestionModelList.ToList().Insert(0, new QuestionsModel() { Id = "", Name = "Please select a security question" }); ViewBag.QuestionList = SecurityQuestionModelList.ToList(); var apiCall = new ApiCallerIndustry(_apiUrl.SSChurch); IndustryList = apiCall.GetAll(); var IndustryModelList = from industry in IndustryList select new IndustryModel() { Id = industry.IndustryId, Name = industry.IndustryName }; ViewBag.IndustryList = IndustryModelList.ToList(); if (model.IndustryId == 0) { throw new Exception("Industry must be selected"); } if (string.IsNullOrWhiteSpace(model.OrganizationName)) { throw new Exception("Organization name is required"); } } catch (Exception ex) { errorMessage = ex.Message; } ViewBag.ErrorMessage = errorMessage; if (!string.IsNullOrEmpty(errorMessage)) { return(View("RegisterOrganization", model)); } else { return(View("Register", model)); } }
public static List <SecurityQuestion> GetSecurityQuestions(string url) { var apiCallQuestion = new ApiCallerSecurityQuestions(url); return(apiCallQuestion.GetAllSecurityQuestions()); }
public async Task <IActionResult> Register(RegisterModel model) { string errorMessage = string.Empty; try { var apiSecQCall = new ApiCallerSecurityQuestions(_apiUrl.SSAuth); var SecurityQuestionsList = apiSecQCall.GetAllSecurityQuestions(); var SecurityQuestionModelList = from secQuestion in SecurityQuestionsList select new QuestionsModel() { Id = secQuestion.SecurityQuestionId.ToString(), Name = secQuestion.Question }; ViewBag.QuestionList = SecurityQuestionModelList.ToList(); // Get Auth Group by name var apiCall = new ApiCallerAuthGroup(_apiUrl.SSAuth); AuthGroup authGroupResult = apiCall.GetAuthGroupByGroupName("NP"); // Get Role by name var apiCallRole = new ApiCallerRole(_apiUrl.SSAuth); Role roleResult = apiCallRole.GetRoleByName("Admin"); var userInfoObject = new AuthUser() { AuthGroupId = authGroupResult.AuthGroupId, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, LoginId = model.Email, Password = model.Password, Status = "A", UserAdded = "Admin@SS", UserRole = new List <UserRole> { new UserRole() { RoleId = roleResult.RoleId, UserAdded = "Admin@SS" } }, UserSecurityQuestion = new List <UserSecurityQuestion> { new UserSecurityQuestion() { SecurityQuestionId = model.Question1, Answer = model.Answer1, UserAdded = "Admin@SS" }, new UserSecurityQuestion() { SecurityQuestionId = model.Question2, Answer = model.Answer2, UserAdded = "Admin@SS" }, new UserSecurityQuestion() { SecurityQuestionId = model.Question3, Answer = model.Answer3, UserAdded = "Admin@SS" } } }; // Register User var apiAuth = new ApiCallerAuthUser(_apiUrl.SSAuth); var userResult = apiAuth.RegisterUser(userInfoObject); // Add Organization var apiOrg = new ApiCallerOrganization(_apiUrl.SSChurch); var orgResult = apiOrg.PostAddOrganization(new Organization { Name = model.OrganizationName, IndustryId = model.IndustryId, Phone = model.OrgPhone, Email = model.OrgEmail, UserAdded = "Admin@SS" }); // Add User Org var apiUserOrg = new ApiCallerUserOrganization(_apiUrl.SSChurch); var userOrgResult = apiUserOrg.PostAddUserOrganization(new UserOrganization { OrganizationId = orgResult.OrganizationId, AuthUserId = userResult.AuthUserId, UserAdded = "Admin@SS" }); // Handle Claims var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, model.Email), new Claim(ClaimTypes.Name, string.Concat(model.FirstName, model.LastName)), new Claim(ClaimTypes.Surname, model.LastName), new Claim(ClaimTypes.GivenName, model.FirstName), new Claim(ClaimTypes.Email, model.Email), new Claim(ClaimTypes.Role, "Admin"), new Claim("OrganizationName", model.OrganizationName), new Claim("OrganizationId", orgResult.OrganizationId.ToString()) }; var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var principal = new ClaimsPrincipal(identity); await HttpContext.SignInAsync(principal); } catch (Exception ex) { errorMessage = ex.Message; } ViewBag.ErrorMessage = errorMessage; if (!string.IsNullOrEmpty(errorMessage)) { return(View("Register")); } else { return(RedirectToAction("Display", "Dashboard")); } }