private Task <Dictionary <string, ControllerDetail> > ResultInvoke(IList <ControllerDetail> objControllers, ReuseableParams objReuseableParams, List <ControllerDetail> lstApsExtraCompsInvoker) { Dictionary <string, ControllerDetail> result = new Dictionary <string, ControllerDetail>(); MethodInvoke methodInvoke = new MethodInvoke(); foreach (ControllerDetail item in objControllers) { ControllerDetail controllerDetail = methodInvoke.Execute(item, objReuseableParams, lstApsExtraCompsInvoker); if (!result.ContainsKey(controllerDetail.ComponentID.Trim())) { result.Add(controllerDetail.ComponentID.Trim(), item); } } return(Task.FromResult(result)); }
public async Task <IActionResult> Login(LoginViewModel model) { WebBuilderController webBuilderController = new WebBuilderController(); IList <ControllerDetail> controllerDetails = await webBuilderController.GetMethodDetails("login", GetSiteID); MethodInvoke methodInvoke = new MethodInvoke(); //if (controllerDetails?.Count > 0) // methodInvoke.Execute(controllerDetails[0], GetReuseableParams(_memoryCache), new List<ControllerDetail>()); string _loginTryCount = string.Format("loginTryCount{0}", model.UserEmail); await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); string loginError = "/login" + CultureURL + "?ReturnUrl=" + model.ReturnURL; if (ModelState.IsValid) { int tryCount = 1; string tryCountStr = TempData[_loginTryCount]?.ToString(); if (tryCountStr != null) { tryCount = int.Parse(tryCountStr) + 1; } //process for lockout if (tryCount >= 10) { OperationStatus rs = new OperationStatus() { Message = "Account locked out" }; if (tryCount == 10) { var lockout = new { UserName = model.UserEmail, }; rs = await _apiClient.PostAsync <OperationStatus>(lockout, APIURL.IdentityBaseUri + IdentityAPI.Account.LockOutAccount, true, false); } TempData[_loginTryCount] = tryCount; ActionMessage(rs.Message, MessageType.Error); return(Redirect(loginError)); } if (tryCount >= 3) // process for captcha { SettingHelper settingHelper = new SettingHelper(); Dictionary <string, string> settingValues = settingHelper.GetSettingValuesByKeys(string.Format("{0},{1}", SettingKeys.CaptchaServer, SettingKeys.CaptchaType)); loginError += "&captcha=true&type=" + settingValues[SettingKeys.CaptchaType]; if (tryCount > 3) { _captchaServer = settingValues[SettingKeys.CaptchaServer]; var rs = await ValidateCaptcha(model.cbuildercaptcharesponse, model.CaptchaAnswer); if (!rs.IsSuccess) { ActionMessage(rs.Message, MessageType.Error); return(Redirect(loginError)); } } } var obj = new { username = model.UserEmail, password = model.UserPassword }; //UserAuthenticateResponse userAuth = await _apiClient.PostAsync<UserAuthenticateResponse>(obj, APIURL.IdentityBaseUri + IdentityAPI.Account.PasswordSignInAsync, true, false); UserAuthenticateResponse userAuth = new UserAuthenticateResponse() { IsAuthenticate = true, AccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9oYXNoIjoiNTc0M2MxMDMtNTIwOS00ZGU1LTgwODAtYmI5MDQxM2JjNzIwIiwibmFtZWlkIjoiMDJDMTU3RUQtQzg4MS00N0VGLUFENEQtQUQyMDIzQzJFNzA0IiwidW5pcXVlX25hbWUiOiJzdXBlcnVzZXJAY29udGVudGRlci5jb20iLCJncm91cHNpZCI6IjE2MCIsInJvbGUiOiJTdXBlciBBZG1pbiIsIm5iZiI6MTYwMjIzNzI0MSwiZXhwIjoxNjAyMjQwODQxLCJpYXQiOjE2MDIyMzcyNDEsImlzcyI6IkNJZGVudGl0eVNlcnZlciJ9.Kg7GQmeQl5us8RXl66h6nccxMatXMI95H4meIMZ9_-0", RefreshToken = "45dbb014bedf499897b0d0575ded96ac", UsersRoles = "Super Admin", UserID = "02C157ED-C881-47EF-AD4D-AD2023C2E704", Message = "Authenticated Successfully." }; if (userAuth == null) { ActionMessage("Identity server not working", MessageType.Warning); return(Redirect(loginError)); } else if (userAuth.IsAuthenticate) { if (string.IsNullOrEmpty(model.ReturnURL)) { RoleManager _role = new RoleManager(); model.ReturnURL = await _role.GetRoleRedirectURL(userAuth.UsersRoles, GetSiteID); if (model.ReturnURL == null) { model.ReturnURL = "/dashboard/dashboard/index" + CultureURL; } else { model.ReturnURL = model.ReturnURL + CultureURL; } } await AuthenticateUser(userAuth, model.ReturnURL); TempData[_loginTryCount] = 0; if (controllerDetails?.Count > 0) { var reusableParam = GetReuseableParams(_memoryCache); reusableParam.UserName = model.UserEmail; foreach (var item in controllerDetails) { methodInvoke.Execute(item, GetAPIParams(model.UserEmail, userAuth.UsersRoles), new List <ControllerDetail>()); } } return(Redirect(model.ReturnURL)); } else { TempData[_loginTryCount] = tryCount; ActionMessage(userAuth.Message, MessageType.Warning); return(Redirect(loginError)); } } ShowModelStateErorr(); return(Redirect(loginError)); }
public async Task <IActionResult> Register(RegisterViewModel model) { //model.ReturnURL = string.IsNullOrEmpty(model.ReturnURL) ? "/login" + CultureURL : model.ReturnURL; string RegistrationURL = "/register" + CultureURL; OperationStatus status = new OperationStatus(); if (ModelState.IsValid) { SettingHelper settingHelper = new SettingHelper(); Dictionary <string, string> settingValues = settingHelper.GetSettingValuesByKeys(UserSettingKeys.GetAllKeys); bool CaptchaEnabled = settingValues[UserSettingKeys.Captcha] == "true"; if (CaptchaEnabled) { _captchaServer = settingValues[UserSettingKeys.CaptchaServer]; var res = await ValidateCaptcha(model.Cbuildercaptcharesponse, model.Captcha); if (!res.IsSuccess) { ActionMessage(res.Message, MessageType.Error); return(Redirect(RegistrationURL)); } } string roleName = settingValues[UserSettingKeys.RegistrationRoleID]; UserPostViewModel user = new UserPostViewModel(); string method = APIURL.IdentityBaseUri + IdentityAPI.AnonomousUser.Create; user.ID = null; user.UserName = model.Email; user.Password = model.Password; user.ConfirmPassword = model.Password; user.Email = model.Email; user.Enabled = settingValues[UserSettingKeys.EmailVerification] == "false"; IEnumerable <string> userInRoles = new List <string> { roleName }; user.UserInRoles = userInRoles; status = await _apiClient.PostAsync <OperationStatus>(user, method, true, false); if (status.IsSuccess) { JObject obj = status.Result as JObject; UserRegisterRS resUser = obj.ToObject <UserRegisterRS>(); if (!user.Enabled) { SendActivationEmail(model, resUser.Code, resUser.ID); status.Message = "Registration success. Check email on " + model.Email + " to verify your accout."; } if (model.IsSubscribe) { AddUserAsSubcriber(model); } CreateProfile(model, resUser.ID); ActionMessage(status.Message, MessageType.Success); WebBuilderController webBuilderController = new WebBuilderController(); IList <ControllerDetail> controllerDetails = await webBuilderController.GetMethodDetails("register", GetSiteID); MethodInvoke methodInvoke = new MethodInvoke(); if (controllerDetails?.Count > 0) { var reusableParam = GetReuseableParams(_memoryCache); reusableParam.UserName = model.Email; foreach (var item in controllerDetails) { methodInvoke.Execute(item, reusableParam, new List <ControllerDetail>()); } } if (string.IsNullOrEmpty(model.ReturnURL)) { RoleManager _role = new RoleManager(); model.ReturnURL = await _role.GetRoleRedirectURL(roleName, GetSiteID); if (model.ReturnURL == null) { model.ReturnURL = "/dashboard/dashboard/index" + CultureURL; } else { model.ReturnURL = model.ReturnURL + CultureURL; } } return(Redirect(model.ReturnURL)); } } else { status.Message = GetModelStateErorr(); } ActionMessage(status.Message, MessageType.Error); return(Redirect(RegistrationURL)); }