private int GetClientId() { var acctName = RouteData.Values["account"] as string; if (String.IsNullOrWhiteSpace(acctName)) { throw new ArgumentException("Conta não encontrada."); } var acct = ModRepository.GetAccountByName(acctName); if (acct == null) { throw new ArgumentException("Conta não encontrada."); } using (var db = new CloudTalkModuleEntities()) { var entry = db.StaticModule_CloudTalk.FirstOrDefault(c => c.AccountId == acct.Id); if (entry == null) { throw new ArgumentException("Dados de atendimento não encontrados."); } return(entry.CloudTalkId); } }
public ActionResult Login() { var subdomain = Request.Url.GetSubDomain(); if (!String.IsNullOrWhiteSpace(subdomain) && subdomain != "www") { var acct = ModRepository.GetAccountByName(subdomain); if (acct == null) { ModelState.AddModelError("_FORM", "Conta não encontrada."); return(View("Login")); } if (!String.IsNullOrWhiteSpace(acct.Logo)) { ViewData["accountlogo"] = Url.Content(acct.Logo); } } if (TempData["_FORM"] != null) { ModelState.AddModelError("_FORM", TempData["_FORM"].ToString()); } return(View("Login")); }
public ActionResult EditAccount(string id) { Account acct = null; if (Roles.IsUserInRole("sysadmin")) { acct = ModRepository.GetAccountByName(id); } else if (Roles.IsUserInRole("administrators")) { var userId = (Guid)Membership.GetUser().ProviderUserKey; acct = ModRepository.GetUserAccounts(userId).FirstOrDefault(acc => acc.SubdomainName == id); } if (acct == null) { TempData["Message"] = "Conta não encontrada."; return(RedirectToAction("Index", "Home")); } return(View(new AccountViewModel { Id = acct.Id, Logo = acct.Logo, Name = acct.Name, Subdomain = acct.SubdomainName, Users = acct.Users.Select(u => u.UserName).ToList() })); }
public ActionResult Create(ModulesViewModel _model) { if (!ModelState.IsValid) { _model.DataTypeList = GetDataTypeList(); return(View(_model)); } if (_model.Fields.Count(f => f.ShowInListMode) == 0) { TempData["Message"] = "Pelo menos um dos campos deve ser visível na listagem."; _model.DataTypeList = GetDataTypeList(); return(View(_model)); } // retrieve the current account name and associate with the newly created module var acctName = RouteData.Values["account"] as string; if (String.IsNullOrWhiteSpace(acctName)) { TempData["Message"] = "Conta não encontrada."; return(View(_model)); } Module newModule = new Module() { DisplayName = _model.DisplayName, ModuleName = _model.DisplayName.EscapeName(), User = ModRepository.GetUserByName(Membership.GetUser().UserName), // associate the module with the current logged in user Account = ModRepository.GetAccountByName(acctName), ModuleType = _model.Type }; _model.Fields.ToList().ForEach(f => { var newField = new Field { DisplayName = f.FieldDisplayName, FieldName = f.FieldDisplayName.EscapeName(), FieldDataType = ModRepository.GetDataTypeByName(f.DataType), IsReadOnly = f.IsReadOnly, IsRequired = f.IsRequired, ShowInListMode = f.ShowInListMode }; if (f.Metadata != null) { newField.AddMetadata(f.Metadata); } newModule.Fields.Add(newField); }); ModRepository.AddModule(newModule); TempData["Message"] = "Módulo salvo com sucesso."; return(RedirectToAction("Index", "Home")); }
public ActionResult Login(string username, string password, bool rememberMe, string returnUrl) { if (!ValidateLogOn(username, password)) { return(Login()); } // Make sure we have the username with the right capitalization // since we do case sensitive checks for OpenID Claimed Identifiers later. username = this.MembershipService.GetCanonicalUsername(username); // if the user is logging in using the pattern http://<accountname>.dovercms.com, // we'll check var subdomain = Request.Url.GetSubDomain(); if (!String.IsNullOrWhiteSpace(subdomain)) { var acct = ModRepository.GetAccountByName(subdomain); var user = acct.Users.FirstOrDefault(a => a.UserName == username); if (user == null) { ModelState.AddModelError("_FORM", "Nome de usuário ou senha incorreta."); return(Login()); } } FormsAuth.SignIn(username, rememberMe); TempData["Message"] = "Bem vindo(a), " + username + "."; if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } return(RedirectToAction("Index", "Home")); }
public ActionResult Register(string userName, string email, string password, string confirmPassword) { if (!CreateNewUser(userName, email, password, confirmPassword)) { return(View()); } var acctName = RouteData.Values["account"] as string; // associate the created user with the current account if (!String.IsNullOrWhiteSpace(acctName)) { var createdUser = ModRepository.GetUserByName(userName); var acct = ModRepository.GetAccountByName(acctName); acct.Users.Add(createdUser); ModRepository.Save(); } TempData["Message"] = "Usuário " + userName + " criado com sucesso."; return(RedirectToAction("Index", "Home")); }