public ActionResult Login(LoginModel AccountOjb) { if (AccountOjb.Username != null && AccountOjb.Password != null) { AccountService.Account account = new AccountService.Account(); account = serv.Authenticate(AccountOjb.Username, getMd5Hash(AccountOjb.Password)); if (account == null) { ViewBag.LoginFail = "Tên đăng nhập hoặc tài khoản không đúng"; return(RedirectToAction("Login", "Account")); } else { Session["username"] = AccountOjb.Username; Session["userid"] = serv.findById(account.id).id; if (Session["cart"] != null) { return(RedirectToAction("Index", "Checkout")); } else { return(RedirectToAction("AllProduct", "Product")); } } } ViewBag.LoginFail = "Vui lòng nhập chính xác thông tin"; return(RedirectToAction("Login", "Account")); }
public ActionResult Login(LoginModel AccountOjb) { if (AccountOjb.Username != null && AccountOjb.Password != null) { AccountService.Account account = new AccountService.Account(); account = serv.Authenticate(AccountOjb.Username, getMd5Hash(AccountOjb.Password)); if (account == null) { ViewBag.LoginFail = "Tên đăng nhập hoặc tài khoản không đúng"; return RedirectToAction("Login", "Account"); } else { Session["username"] = AccountOjb.Username; Session["userid"] = serv.findById(account.id).id; if (Session["cart"] != null) { return RedirectToAction("Index", "Checkout"); } else { return RedirectToAction("AllProduct", "Product"); } } } ViewBag.LoginFail = "Vui lòng nhập chính xác thông tin"; return RedirectToAction("Login", "Account"); }
public ActionResult UpdatePassword() { //not sign in if (Session["userid"] == null) { ViewBag.LoginFaild = "Vui lòng đăng nhập"; return(RedirectToAction("Login", "Account")); } else { string CurrentPassword = Request["CurrentPassword"]; string ReNewPassword = Request["ReNewPassword"]; string NewPassword = Request["NewPassword"]; long AccountId = Convert.ToInt64(Session["userid"]); // find account AccountService.Account account = serv.findById(Convert.ToInt64(AccountId)); // indentify account if (account.Password != getMd5Hash(CurrentPassword)) { Session["ErrorMessage"] = "Password này không đúng với password hiện tại"; return(RedirectToAction("MyAccount", "Account")); } else { // compare two new password if (NewPassword != ReNewPassword) { Session["ErrorMessage"] = "Password này không đúng với password hiện tại"; return(RedirectToAction("MyAccount", "Account")); } else { // set new password to current account account.Password = getMd5Hash(NewPassword); bool UpdateResult = serv.update(account); if (UpdateResult == false) { Session["ErrorMessage"] = "Đổi mật khẩu thất bại"; } else { Session["SuccessMessage"] = "Đổi password thành công"; } return(RedirectToAction("MyAccount", "Account")); } } } }
public ActionResult MyAccount() { AccountService.Account Account = new AccountService.Account(); if (Session["userid"] == null) { return(RedirectToAction("Login", "Account")); } else { Account = serv.findById(Convert.ToInt64(Session["userid"])); if (Account == null) { ViewBag.LoginSucess = "Account doesn't exist!"; return(RedirectToAction("Login", "Account")); } } return(View(Account)); }
public ActionResult Register(AccountService.Account AccountObj) { // set data default AccountObj.Status = true; AccountObj.CreatedAt = DateTime.Now; AccountObj.GroupId = "admin"; // insert an account long InsertResult = serv.insert(AccountObj); if (InsertResult == -1) // if it's not work { return(RedirectToAction("Index", "Home")); } else { ViewBag.LoginSucess = "Đăng ký thành công"; return(RedirectToAction("Login", "Account", InsertResult)); } }
public ActionResult UploadFile(HttpPostedFileBase photo) { if (!isValidContentype(photo.ContentType)) { ViewBag.Error = "Chỉ được phép upload những file png, jpeg, gif, jpg"; return(RedirectToAction("MyAccount", "Account")); } else if (!isValidContentLength(photo.ContentLength)) { ViewBag.Error = "Dung lượng hình quá lớn. Kích cỡ phù hợp là nhỏ hơn 1 MB"; return(RedirectToAction("MyAccount", "Account")); } else { if (photo.ContentLength > 0) { var fileName = Path.GetFileName(photo.FileName); var path = Path.Combine(Server.MapPath("~/Content/Upload/Avatar"), fileName); photo.SaveAs(path); AccountService.Account account = serv.findById(Convert.ToInt64(Session["userid"])); // set new information account.Avatar = fileName; bool UpdateResult = serv.update(account); if (UpdateResult == false) { Session["ErrorMessage"] = "Cập nhật avatar thất bại"; } else { Session["SuccessMessage"] = "Cập nhật avartar thành công"; } return(RedirectToAction("MyAccount", "Account")); } } return(RedirectToAction("MyAccount", "Account")); }
public ActionResult UpdateInformation() { //not sign in if (Session["userid"] == null) { ViewBag.LoginFaild = "Vui lòng đăng nhập"; return(RedirectToAction("Login", "Account")); } else { string Name = Request["Fullname"]; string Address = Request["Address"]; string Phone = Request["Phone"]; string Email = Request["Email"]; long AccountId = Convert.ToInt64(Session["userid"]); // find account AccountService.Account account = serv.findById(Convert.ToInt64(AccountId)); // set new information account.Fullname = Name; account.Address = Address; account.Phone = Phone; account.Email = Email; bool UpdateResult = serv.update(account); if (UpdateResult == false) { Session["ErrorMessage"] = "Cập nhật thông tin thất bại"; } else { Session["SuccessMessage"] = "Cập nhật thông tin thành công"; } return(RedirectToAction("MyAccount", "Account")); } }
private void ApplyHistoryRemoveAccountSettingsSheduleTime(IList<long> ids) { if (ids == null) return; AccountService.Account[] itemsToChange = new AccountService.Account[] { }; lock (Accounts) { var itemsToDelete = Accounts .SelectMany(a => a.Settings.SheduleTimes.Select(c => new { Account = a, Time = c })) .Join(ids, a => a.Time.Id, id => id, (a, id) => a) .GroupBy(i => i.Account) .Select(g => new { Account = g.Key, Times = g.Select(i => i.Time).ToArray() }) .ToArray(); foreach (var i in itemsToDelete) foreach (var c in i.Times) i.Account.Settings.SheduleTimes.Remove(c); itemsToChange = itemsToDelete.Select(i => i.Account).ToArray(); } if (itemsToChange.Length > 0) OnAccountsChanged(this, new ListItemsEventArgs<AccountService.Account>(itemsToChange, ChangeAction.Change)); }
private void ApplyHistoryRemoveAccount(IList<Guid> ids) { if (ids == null) return; AccountService.Account[] itemsToDelete = new AccountService.Account[] { }; lock (Accounts) { itemsToDelete = Accounts.Join(ids, a => a.Id, id => id, (a, id) => a).ToArray(); foreach (var i in itemsToDelete) Accounts.Remove(i); } if (itemsToDelete.Length > 0) OnAccountsChanged(this, new ListItemsEventArgs<AccountService.Account>(itemsToDelete, ChangeAction.Remove)); }
private void RaiseAccountInitialize(AccountService.Account[] accounts) { AccountService.Account[] oldAccounts = new AccountService.Account[] { }; lock (Accounts) { oldAccounts = Accounts.ToArray(); Accounts.Clear(); } if (oldAccounts.Length > 0) OnAccountsChanged(this, new ListItemsEventArgs<AccountService.Account>(oldAccounts, ChangeAction.Remove)); lock(Accounts) { Accounts.AddRange(accounts); } if (accounts.Length > 0) OnAccountsChanged(this, new ListItemsEventArgs<AccountService.Account>(accounts, ChangeAction.Add)); }
public ActionResult MyAccount() { AccountService.Account Account = new AccountService.Account(); if (Session["userid"] == null) { return RedirectToAction("Login", "Account"); } else { Account = serv.findById(Convert.ToInt64( Session["userid"])); if (Account == null) { ViewBag.LoginSucess = "Account doesn't exist!"; return RedirectToAction("Login", "Account"); } } return View(Account); }