public ActionResult Create([Bind(Include = "id,username,password,question,answer,roldId,firstName,lasName,gender,country,mobile,address")] Account account) { var i = db.Accounts.Count(acc => acc.username.Equals(account.username)); if (ModelState.IsValid) { if (i < 1) { AccountViewModels avm = new AccountViewModels(); avm.accountView = new Account(); avm.accountView.username = account.username; avm.accountView.password = EncryptMD5.Encrypt(account.password); avm.accountView.question = account.question; avm.accountView.answer = account.answer; avm.accountView.roldId = account.roldId; avm.accountView.firstName = account.firstName; avm.accountView.lastName = account.lastName; avm.accountView.gender = account.gender; avm.accountView.country = account.country; avm.accountView.mobile = account.mobile; avm.accountView.address = account.address; db.Accounts.Add(avm.accountView); db.SaveChanges(); return(View("Index")); } ModelState.AddModelError("", "UserName Has been used"); } ViewBag.roldId = new SelectList(db.Roles, "id", "name", account.roldId); return(View(account)); }
public async Task <ActionResult> Login(AccountViewModels model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); Response.Redirect(Request.RawUrl); return(View(model)); } }
//[MultipleButton(Name = "action", Argument = "Edit")] public ActionResult Edit([Bind(Include = "username,password,question,answer,roldId,firstName,lasName,gender,country,mobile,address")] Account account) { //ProjectWebGreeting.Common.EncryptMD5.Decrypt(account.password); if (ModelState.IsValid) { AccountViewModels avm = new AccountViewModels() { accountView = new Account() { username = account.username, password = EncryptMD5.Encrypt(account.password), question = account.question, answer = account.answer, roldId = account.roldId, firstName = account.firstName, lastName = account.lastName, gender = account.gender, country = account.country, mobile = account.mobile, address = account.address } }; db.Entry(avm.accountView).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.roldId = new SelectList(db.Roles, "id", "name", account.roldId); return(View(account)); }
public ActionResult MyProfile(Account account) { AccountViewModels avm = new AccountViewModels() { accountView = new Account() { id = account.id, username = MySession.Username, password = EncryptMD5.Encrypt(account.password), question = account.question, answer = account.answer, roldId = account.roldId, firstName = account.firstName, lastName = account.lastName, gender = account.gender, country = account.country, mobile = account.mobile, address = account.address } }; db.Entry(avm.accountView).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Login(AccountViewModels model, string returnUrl) { try { if (ModelState.IsValid) { var loginInfo = this.databaseManager.LoginByUsernamePassword(model.Username, model.Password).ToList(); if (loginInfo != null && loginInfo.Count() > 0) { var loginDetails = loginInfo.First(); this.SignInUser(loginDetails.username, false); return(this.RedirectToLocal(returnUrl)); } else { ModelState.AddModelError(string.Empty, "Invalid userName or Password"); } } } catch (Exception ex) { Console.WriteLine(ex); } return(this.View(model)); }
public void DeleteAccount() { try { if (Account == null) { return; } if (!DialogService.Confirm("Are you sure you want to delete this account even though it cannot be undone?")) { return; } if (Account.IsPersisted) { StorageService.DeleteAccount(Password, Account.AccountName); } Status = $"'{Account.AccountName}' account deleted!"; AccountViewModels.Remove(Account); Account = AccountViewModels.FirstOrDefault(); } catch (Exception e) { DialogService.Exception(e); } }
public void ExportAccounts() { try { if (AccountViewModels.Any(vm => vm.HasChanges)) { DialogService.Notify("You have unsaved changes. Please save changes before exporting accounts."); return; } using (var dialog = new FolderBrowserDialog()) { if (dialog.ShowDialog() != DialogResult.OK) { return; } var filePath = $@"{dialog.SelectedPath}\exported-accounts-{DateTime.Now.Ticks}.json"; string encrypt(string text) => CryptoService.Encrypt(StorageService.GetSecretKey(Password), text); var data = AccountViewModels.Select(vm => vm.ViewModelToModel(encrypt)); File.WriteAllText(filePath, JsonConvert.SerializeObject(data)); Status = "Accounts exported..."; } } catch (Exception e) { DialogService.Exception(e); } }
public ActionResult Login(AccountViewModels model, string returnUrl) { string errrMsg = "Invalid login attempt. Your user or password is wrong"; if (!ModelState.IsValid) { ModelState.AddModelError("", errrMsg); return(View(model)); } var userInformation = model.validateGG(model.Server, model.UserName, model.Password); if (userInformation != null) { DataRow rowUser = userInformation.Rows[0]; if (rowUser["is_enabled"].ToString() == "Y") { Session["server"] = model.Server; Session["username"] = model.UserName; Session["userkey"] = model.Password; FormsAuthentication.SetAuthCookie(model.UserName, false); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "The user is disabled in GRIN-Global server"); return(View(model)); } } ModelState.AddModelError("", errrMsg); return(View(model)); }
public ActionResult Login(AccountViewModels model, string returnUrl) { UserSys user = new UserSys(); try { if (!ModelState.IsValid) { return(View(model)); } user = db.UserSys.Where(p => p.Email == model.Email && p.Password == model.Password).FirstOrDefault(); if (user == null) { TempData["MsgError"] = "The email and/or password entered is invalid. Please try again."; return(RedirectToAction("Login")); } TempData["Role"] = user.UserRoleId; return(RedirectToRoute(new { controller = "Customers", action = "Index" })); } catch { return(View()); }; }
public ActionResult UserProfileModel(UserProfile userProfile) { if (ModelState.IsValid) { AccountViewModels.UpdateUserProfile(userProfile); ViewBag.Message = "Profile is saved successfully."; } return(View()); }
public void AddAccount() { var viewModel = new AccountViewModel(); AccountViewModels.Add(viewModel); Account = viewModel; Status = string.Empty; }
private void HandleAccountDeletedEvent(string accountName) { foreach (AccountViewModel accountVm in AccountViewModels) { if (accountVm.Account.AccountName == accountName) { Application.Current.Dispatcher.Invoke(() => { AccountViewModels.Remove(accountVm); }); break; } } }
/// <summary> /// 展示所有用户 /// </summary> /// <returns></returns> public async Task <IActionResult> ShowAllUser() { var users = await _userService.GetAllUser(); AccountViewModels models = new AccountViewModels(); models.Roles = await _roleSever.GetRolesAsync(); models.Users = users; return(View(models)); }
private async Task <IActionResult> BuildDisplayAsync(AccountViewModels model) { if (model == null) { model = new AccountViewModels(); } var roles = await _roleSever.GetRolesAsync(); model.Roles = roles; return(View(model)); }
public void AccountViewModel_Template_Test() { var template = new AccountViewModels(new SmartAppInfo { Id = ApplicationId }); var output = template.TransformText(); Assert.NotNull(output); Assert.NotEmpty(output); Assert.Contains($"namespace {ApplicationId}.Backend.Models", output); }
public override void CanClose(Action <bool> callback) { if (AccountViewModels.Any(vm => vm.HasChanges)) { callback(DialogService.Confirm("You have unsaved changes. Are you sure you want to exit?")); return; } callback(true); }
private void HandleNewAccountAddedEvent(Account newAccount) { if (newAccount == null) { throw new ArgumentNullException("newAccount"); } AccountViewModel newAccountViewModel = new AccountViewModel(newAccount); Application.Current.Dispatcher.Invoke(() => { AccountViewModels.Add(newAccountViewModel); }); }
public async Task <IActionResult> Index(string user) { if (_userManager.FindByNameAsync(user) != null) { AccountViewModels AccountModel = new AccountViewModels(); AccountModel.AccountUser = await _userManager.FindByNameAsync(user); AccountModel.ListCompany = db.Companies.Where(u => u.OwnerName == user); AccountModel.AchievementUser = db.Achievements.FirstOrDefault(a => a.OwnerName == user); AccountModel.ListUserBonus = db.UserBonuses.Where(n => n.OwnerName == user); return(View(AccountModel)); } return(RedirectToAction("Index", "Home")); }
public void ImportAccounts() { try { if (AccountViewModels.Any(vm => vm.HasChanges)) { DialogService.Notify("You have unsaved changes. Please save changes before importing accounts."); return; } using (var dialog = new OpenFileDialog { Filter = "JSON files (*.json)|*.json" }) { if (dialog.ShowDialog() != DialogResult.OK) { return; } var json = File.ReadAllText(dialog.FileName); var data = JsonConvert.DeserializeObject <Dtos.AccountDto[]>(json); string dencrypt(string text) => CryptoService.Decrypt(StorageService.GetSecretKey(Password), text); foreach (var item in data) { var found = AccountViewModels.Any(vm => vm.AccountName == item.AccountName); item.AccountName = found ? $"{item.AccountName} - duplicate" : item.AccountName; AccountViewModels.Add(new AccountViewModel(item, dencrypt, true)); } Account = AccountViewModels.FirstOrDefault(); Status = "Accounts imported..."; } } catch (Exception e) { DialogService.Exception(e); } }
public async Task <IActionResult> Register(AccountViewModels accountViewModel) { if (!ModelState.IsValid) { var email = new IdentityUser() { UserName = accountViewModel.Email }; var result = await _userManager.CreateAsync(email, accountViewModel.Password); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } } return(View(accountViewModel)); }
public ActionResult LogOn(AccountViewModels.LogOnModel model, string returnUrl) { //if (ModelState.IsValid) //{ if (MembershipService.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } return this.RedirectToAction("Index", "Home"); } this.ModelState.AddModelError("", "The user name or password provided is incorrect."); return View(model); }
public void LoadAccounts() { if (AccountViewModels == null) { AccountViewModels = new ObservableCollection <AccountViewModel>(); } else { AccountViewModels.Clear(); } List <Account> accounts = AccountManager.Instance.Accounts; foreach (Account acc in accounts) { AccountViewModels.Add(new AccountViewModel(acc)); } }
public async Task <IActionResult> LogIn(AccountViewModels viewModel) { if (ModelState.IsValid) { var result = await _signInManager.PasswordSignInAsync(viewModel.Email, viewModel.Password, false, false); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Nie można się zalogować!"); } } return(View(viewModel)); }
public async Task <ActionResult> Login(AccountViewModels model) { var user = await _userRepository.GetLoginUserAsync(model.Username, model.Password); if (user == null) { ModelState.AddModelError(string.Empty, "کاربر با مدارک ارائه شده موجود نیست."); //ModelState.AddModelError(string.Empty, "The user with supplied credentials does not exist."); } var authManager = HttpContext.GetOwinContext().Authentication; var userIdentity = await _userRepository.CreateIdentityAsync(user); authManager.SignIn(new AuthenticationProperties(), userIdentity); return(RedirectToAction("Index", "Home")); }
public ActionResult Register(AccountViewModels.RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { MembershipService.CreateUser(model.UserName, model.Password, model.Email, "User"); FormsAuthentication.SetAuthCookie(model.UserName, false); return RedirectToAction("Index", "Home"); } catch (ArgumentException ae) { ModelState.AddModelError("", ae.Message); } } // If we got this far, something failed, redisplay form return View(model); }
public void SaveChanges() { try { var canSave = AccountViewModels.All(vm => vm.CanSave()); if (!canSave) { DialogService.Error("Not all accounts are valid. Account Name is required."); return; } var duplicate = AccountViewModels.GroupBy(vm => vm.AccountName).Any(grp => grp.Count() > 1); if (duplicate) { DialogService.Error("Duplicate account names are not allowed."); return; } string encrypt(string text) => CryptoService.Encrypt(StorageService.GetSecretKey(Password), text); foreach (var vm in AccountViewModels) { var model = vm.ViewModelToModel(encrypt); StorageService.UpsertAccount(Password, model); vm.OnPostSave(); } Status = "Accounts saved..."; } catch (Exception e) { DialogService.Exception(e); } }
public async Task <ActionResult> Register(AccountViewModels model) { if (!ModelState.IsValid) { return(View(viewName: "Index")); } var users = await _userRepository.GetAllUsersAsync(); var user = users.SingleOrDefault(u => u.UserName == model.Username || u.Email == model.Email); if (user != null) { ModelState.AddModelError(string.Empty, "کاربر با مدارک ارائه شده موجود است."); //ModelState.AddModelError(string.Empty, "The user with supplied credentials does exist."); } //var completed = await _users.CreateAsync(model); // if (completed) // { // return RedirectToAction("Login", "Profile"); // } var newUser = new UserIdentity() { DisplayName = model.FullName, Email = model.Email, UserName = model.Username, FirstName = model.FullName, LastName = model.FullName, }; await _userRepository.CreateAsync(newUser, model.Password); await _userRepository.AddUserToRoleAsync(newUser, "user"); return(RedirectToAction("Index", "Account")); }
protected override void OnViewReady(object view) { base.OnViewReady(view); try { string dencrypt(string text) => CryptoService.Decrypt(StorageService.GetSecretKey(Password), text); var items = StorageService.GetAllAccounts(Password).OrderBy(x => x.AccountName); foreach (var item in items) { AccountViewModels.Add(new AccountViewModel(item, dencrypt)); } Account = AccountViewModels.FirstOrDefault(); } catch (Exception e) { DialogService.Exception(e); } }
public async Task <ActionResult> ExternalLoginConfirmation(AccountViewModels model, string returnUrl) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Manage")); } if (ModelState.IsValid) { // Obter as informações sobre o usuário do provedor de logon externo var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return(View("ExternalLoginFailure")); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(RedirectToLocal(returnUrl)); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public async Task <ActionResult> Login(AccountViewModels account, string returnUrl) { Account user = await _accountService.FindAsync(account.Username, account.Password); if (user == null) { AddErrors("Invalid username or password"); return(View(account)); } else { ClaimsIdentity claimsIdentity = await _accountService .CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); _authenticationManager.SignOut(); _authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = account.IsRemember }, claimsIdentity); return(RedirectToLocal(returnUrl)); } }
public ActionResult Login(AccountViewModels model, string returnUrl) { if (!this.ModelState.IsValid) { return(this.View(model)); } if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (this.Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(this.Redirect(returnUrl)); } return(this.RedirectToAction("Index", "Home")); } this.ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect."); return(this.View(model)); }
public void LoadAccounts() { if (AccountViewModels == null) { AccountViewModels = new ObservableCollection <AccountViewModel>(); } else { AccountViewModels.Clear(); } List <Account> accounts = AccountManager.Instance.Accounts; foreach (Account acc in accounts) { AccountViewModels.Add(new AccountViewModel(acc)); } // Select the first mailbox of the first account by default. if (AccountViewModels.Count > 0 && AccountViewModels[0].MailboxViewModelTree.Count > 0) { AccountViewModels[0].MailboxViewModelTree[0].IsSelected = true; } }