public JsonResult GetPermissionTree(int roleID) { try { RoleAccount ra = this.db.RoleAccounts.Find(roleID); List <TreeViewNode> ls = new List <TreeViewNode>(); foreach (var i in this.db.Permissions) { TreeViewNode tvn = new TreeViewNode { id = i.ID.ToString(), parent = i.Parent, text = i.Description, state = new Dictionary <string, bool>() }; if (ra != null && roleID != 0 && ra.PermissionID != null && ra.PermissionID.Split(',').Contains(tvn.id.ToString())) { tvn.state.Add("selected", true); } ls.Add(tvn); } return(this.Json(ls)); } catch { return(null); } }
public string UpdateRole(int roleID, string roleName, List <string> listPermissionID) { try { if (listPermissionID == null) { listPermissionID = new List <string>(); } RoleAccount ra = new RoleAccount() { ID = roleID, Role = roleName, PermissionID = string.Join(",", listPermissionID) }; /*if (rs == null) * { * return "Role không tồn tại !!!"; * }*/ RoleAccountDAO.UpdateRole(ra); } catch { return("Update Role không thành công !!!"); } return("success"); }
public IActionResult Regester(Account account, IFormFile photo) { var eaccount = db.Accounts.All(a => a.Email != account.Email && a.Username != account.Username); if (!eaccount) { ViewBag.notice = "your email or username registered"; return(View("Register")); } account.Password = BCrypt.Net.BCrypt.HashPassword(account.Password); account.Status = true; var fileName = DateTime.Now.ToString("MMddyyyyhhmmss") + photo.FileName; var path = Path.Combine(this.ihostingEnvironment.WebRootPath, "account", fileName); var stream = new FileStream(path, FileMode.Create); photo.CopyToAsync(stream); account.Photo = fileName; db.Accounts.Add(account); db.SaveChanges(); var roleAccount = new RoleAccount(); roleAccount.RoleId = 2; roleAccount.AccountId = account.Id; roleAccount.Status = true; db.RoleAccounts.Add(roleAccount); ViewBag.notice = "Register Successful"; db.SaveChanges(); return(View("Register")); }
public IActionResult Register(Account aAccountInfo) { aAccountInfo.Status = true; if (ModelState.IsValid) { bool isSaveAccount = _iAccountManager.Add(aAccountInfo); Account lastAddAccountInfo = _iAccountManager.GetAll().LastOrDefault(); RoleAccount initialRoleAccount = new RoleAccount() { RoleId = 2, AccountId = lastAddAccountInfo.Id, Status = true }; bool isSaveRoleAccount = _iRoleAccountManager.Add(initialRoleAccount); if (isSaveAccount == true && isSaveRoleAccount == true) { return(RedirectToAction("Index", "Login")); } else { ViewBag.ErrorMessage = "Registration has been failed! Try again."; return(View(aAccountInfo)); } } return(View(aAccountInfo)); }
public async Task <IActionResult> Create([Bind("GeneralInformation")] Account account, int[] roleIds) { if (ModelState.IsValid) { foreach (var id in roleIds) { var role = _context.Role.Find(id); RoleAccount roleAccount = new RoleAccount { Role = role, Account = account }; _context.Add(roleAccount); } _context.Add(account); _context.Add(account.GeneralInformation); await _context.SaveChangesAsync(); account.RollNumber = "B19APTECH" + account.AccountId.ToString("D4"); account.Password = account.GeneralInformation.Dob.ToString(); account.EncryptPassword(account.Password); _context.Update(account); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(account)); }
public IActionResult Index(Login loginInfo) { if (ModelState.IsValid) { Account loginAccountInfo = _iAccountManager.GetAll() .Where(a => a.Username == loginInfo.Username && a.Password == loginInfo.Password && a.Status == true) .FirstOrDefault(); if (loginAccountInfo == null) { ViewBag.ErrorMessage = "Invalid Username and Password! Try again."; return(View()); } Role checkRole = _iRoleManager.GetAll().Where(r => r.Id == 1).FirstOrDefault(); RoleAccount checkRoleAndAccount = _iRoleAccountManager.GetAll() .Where(cra => cra.RoleId == checkRole.Id && cra.AccountId == loginAccountInfo.Id && cra.Status == true) .FirstOrDefault(); if (checkRoleAndAccount != null) { HttpContext.Session.SetString("AdminId", loginAccountInfo.Id.ToString()); return(RedirectToAction("Index", "Dashboard")); } else { ViewBag.ErrorMessage = "Invalid Username and Password! Try again."; return(View()); } } return(View(loginInfo)); }
public IActionResult Register(Account account) { var exists = db.Accounts.Count(a => a.Username.Equals(account.Username)) > 0; if (!exists) { account.Password = BCrypt.Net.BCrypt.HashPassword(account.Password); account.Status = true; db.Accounts.Add(account); db.SaveChanges(); // Add Role Customer to New Account var roleAccount = new RoleAccount() { RoleId = 2, AccountId = account.Id, Status = true }; db.RoleAccounts.Add(roleAccount); db.SaveChanges(); return(RedirectToAction("dashboard", "customer")); } else { ViewBag.error = "Username exists"; account = new Account(); return(View("dashboard", "customer")); } }
public IActionResult CreateAccount([FromBody] GeneralInformationWithRoles generalInfoWithRoles, [FromHeader] string Authorization, [FromHeader] string Role) { if (CheckToken(Authorization) == true && CheckPermission(Role) == true) { if (ModelState.IsValid) { Account account = new Account(); account.GeneralInformation = generalInfoWithRoles.GeneralInformation; foreach (var id in generalInfoWithRoles.RoleIds) { var role = _context.Role.Find(id); RoleAccount roleAccount = new RoleAccount { Role = role, Account = account }; _context.Add(roleAccount); } _context.Add(account); _context.Add(account.GeneralInformation); _context.SaveChanges(); account.RollNumber = "B19APTECH" + account.AccountId.ToString("D4"); account.Password = account.GeneralInformation.Dob.ToString("ddMMyy"); account.EncryptPassword(account.Password); _context.Update(account); _context.SaveChanges(); return(new JsonResult(account.GeneralInformation.Dob.ToString("ddMMyy"))); } //return new JsonResult(generalInfoWithRoles); } return(Unauthorized()); }
public IActionResult CustomerLogin(string username, string password) { if (ModelState.IsValid) { Account loginCustomerInfo = _iAccountManager.GetAll() .Where(a => a.Username == username && a.Password == password && a.Status == true).FirstOrDefault(); if (loginCustomerInfo == null) { ViewBag.ErrorMessage = "Username and password not match! Try again."; return(View("CustomerLogin")); } RoleAccount aRoleAccountInfo = _iRoleAccountManager.GetAll() .Where(ra => ra.RoleId == 2 && ra.AccountId == loginCustomerInfo.Id && ra.Status == true).FirstOrDefault(); if (aRoleAccountInfo != null) { HttpContext.Session.SetString("CustomerId", loginCustomerInfo.Id.ToString()); return(RedirectToAction("Index", "ClinteDeshboard")); } else { ViewBag.ErrorMessage = "Username and password not match! Try again."; return(View("CustomerLogin")); } } ViewBag.ErrorMessage = "Username and password are not match! Try again"; return(View("CustomerLogin")); }
/// <summary> /// Initializes a new instance of the <see cref="Account"/> class based on a <see cref="User"/> instance. /// </summary> /// <param name="u">The user.</param> /// <param name="mail">The mail.</param> /// <param name="password">The hash of password.</param> /// <param name="r">The role.</param> public Account(User u, string mail, string password, string firstName, string lastName, RoleAccount r) : base(u) { this.mail = mail; this.password = password; this.firstName = firstName; this.lastName = lastName; //this.dateBirth = dateBirth; this.role = r; }
public Account(User u, string mail, string password, string firstName, string lastName, RoleAccount r, DateTime creationDate, DateTime updateDate, long elapsedTime) : base(u) { this.mail = mail; this.password = password; this.firstName = firstName; this.lastName = lastName; //this.dateBirth = dateBirth; this.role = r; this.creationDate = creationDate; this.updateDate = updateDate; this.elapsedTime = elapsedTime; }
public string checkLogin(string username, string password, RoleAccount roleStr) { SqlConnection conn = new SqlConnection(connStr); String sqlQuery = "select FullName, Status from UserAccount " + "where Username = @username and Password= @password and Role=@role"; SqlCommand command = new SqlCommand(sqlQuery, conn); if (roleStr.ToString().Equals("Admin")) { command.Parameters.AddWithValue("@role", 1); } else { command.Parameters.AddWithValue("@role", 0); } command.Parameters.AddWithValue("@username", username); command.Parameters.AddWithValue("@password", password); if (conn.State == ConnectionState.Closed) { conn.Open(); } SqlDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection); if (dr.HasRows) { dr.Read(); string status = dr.GetString(1); if (status.Equals("Blocked")) { return("UserBlocked"); } else { string fullname = dr.GetString(0); return(fullname); } } return(null); }
public IActionResult Regester(Account account) { account.Password = BCrypt.Net.BCrypt.HashPassword(account.Password); account.Status = true; db.Accounts.Add(account); db.SaveChanges(); var roleAccount = new RoleAccount(); roleAccount.RoleId = 2; roleAccount.AccountId = account.Id; roleAccount.Status = true; db.RoleAccounts.Add(roleAccount); db.SaveChanges(); return(RedirectToAction("login", "customer")); }
public IActionResult OnPost() { account.Password = BCrypt.Net.BCrypt.HashPassword(account.Password); account.Status = true; _context.Accounts.Add(account); _context.SaveChanges(); RoleAccount roleAccount = new RoleAccount { AccountId = account.Id, RoleId = 2, Status = true }; _context.RoleAccounts.Add(roleAccount); _context.SaveChanges(); return(RedirectToPage("login")); }
public IEnumerator ToAccount(string accountJson, Action <Account> a) { JObject parse = JObject.Parse(accountJson); string mail = (string)parse["connection"]["email"]; string password = (string)parse["connection"]["password"]; string firstName = (string)parse["userInformation"]["firstName"]; string lastName = (string)parse["userInformation"]["lastName"]; RoleAccount roleAccount = (RoleAccount)Enum.Parse(typeof(RoleAccount), (string)parse["userInformation"]["accountType"]); DateTime creationDate = (DateTime)parse["createdAt"]; DateTime updateDate = (DateTime)parse["updatedAt"]; long elapsedTime = (long)parse["game"]["elapsedTime"]; User user = new User(); yield return(JSONHelper.Instance.ToUser(accountJson, value => user = value)); Account account = new Account(user, mail, password, firstName, lastName, roleAccount, creationDate, updateDate, elapsedTime); a(account); }
public IActionResult Edit(int?id) { if (HttpContext.Session.GetString("AdminId") != null) { if (id == null) { return(NotFound()); } RoleAccount getRoleAccount = _iRoleAccountManager.GetById(id); Account getSelectedCustomer = _iAccountManager.GetAll() .Where(a => a.Id == getRoleAccount.AccountId).FirstOrDefault(); if (getRoleAccount == null || getSelectedCustomer == null) { return(NotFound()); } return(View(getSelectedCustomer)); } return(RedirectToAction("Index", "Login")); }
public IActionResult Regester(Account account) { var eaccount = db.Accounts.All(a => a.Email != account.Email); if (!eaccount) { ViewBag.notice = "your email registered"; return(View("Register")); } account.Password = BCrypt.Net.BCrypt.HashPassword(account.Password); account.Status = true; db.Accounts.Add(account); db.SaveChanges(); var roleAccount = new RoleAccount(); roleAccount.RoleId = 2; roleAccount.AccountId = account.Id; roleAccount.Status = true; db.RoleAccounts.Add(roleAccount); db.SaveChanges(); return(RedirectToAction("login", "customer")); }
public string InsertRole(int roleID, string roleName, List <string> listPermissionID) { try { if (listPermissionID == null) { listPermissionID = new List <string>(); } var rs = new RoleAccount() { Role = roleName, PermissionID = string.Join(",", listPermissionID) }; RoleAccountDAO.InsertRole(rs); } catch { return("Insert Role không thành công !!!"); } return("success"); }
public IHttpActionResult PostGenerateMember() { try { var memberItems = new List <Member>(); var password = PasswordHashModel.Hash("123456"); var positions = new string[] { "Frontend Developer", "Backend Developer" }; var roles = new RoleAccount[] { RoleAccount.Member, RoleAccount.Employee, RoleAccount.Admin }; var random = new Random(); for (var index = 1; index <= 98; index++) { memberItems.Add(new Member { email = $"mail-{index}@mail.com", password = password, firstname = $"Firstname {index}", lastname = $"Lastname {index}", position = positions[random.Next(0, 2)], role = roles[random.Next(0, 3)], created = DateTime.Now, updated = DateTime.Now }); } var db = new DbEntities(); db.Members.AddRange(memberItems); db.SaveChanges(); return(Ok("Generate successful.")); } catch (Exception ex) { ModelState.AddModelError("Exceptrion", ex.Message); return(BadRequest(ModelState.GetErrorModelState())); } }
public IActionResult EditAccount([FromBody] GeneralInformationWithRoles generalInfoWithRoles, [FromHeader] string Authorization) { if (CheckToken(Authorization) == true) { var account = _context.Account.Find(generalInfoWithRoles.AccountId); var generalInfo = _context.GeneralInformation.Find(generalInfoWithRoles.AccountId); account.RollNumber = "B19APTECH" + account.AccountId.ToString("D4"); generalInfo.Phone = generalInfoWithRoles.GeneralInformation.Phone; generalInfo.Address = generalInfoWithRoles.GeneralInformation.Address; generalInfo.Email = generalInfoWithRoles.GeneralInformation.Email; account.UpdatedAt = DateTime.Today; if (generalInfoWithRoles.Password != null) { account.EncryptPassword(generalInfoWithRoles.Password); } if (generalInfoWithRoles.RoleIds != null) { var OldRoleAccount = _context.RoleAccount.Where(ora => ora.AccountId == generalInfoWithRoles.AccountId); _context.RoleAccount.RemoveRange(OldRoleAccount); } foreach (var roleId in generalInfoWithRoles.RoleIds) { var role = _context.Role.Find(roleId); RoleAccount roleAccount = new RoleAccount { Role = role, Account = account }; _context.RoleAccount.Add(roleAccount); } _context.Account.Update(account); _context.GeneralInformation.Update(generalInfo); _context.SaveChanges(); return(new JsonResult(generalInfoWithRoles)); } return(Unauthorized()); }
public async Task <IActionResult> Edit(int id, [Bind("AccountId,RollNumber,Password,Salt,CreatedAt,UpdatedAt,Status")] Account account, int[] roleIds, int[] clazzIds) { if (id != account.AccountId) { return(NotFound()); } if (ModelState.IsValid) { try { if (roleIds != null) { var OldRoleAccount = _context.RoleAccount.Where(ora => ora.AccountId == id); _context.RoleAccount.RemoveRange(OldRoleAccount); } if (clazzIds != null) { var OldStudentClazz = _context.StudentClazz.Where(osc => osc.AccountId == id); _context.StudentClazz.RemoveRange(OldStudentClazz); } foreach (var roleId in roleIds) { var role = _context.Role.Find(roleId); RoleAccount roleAccount = new RoleAccount { Role = role, Account = account }; _context.Update(roleAccount); } foreach (var clazzId in clazzIds) { var clazz = _context.Clazz.Find(clazzId); StudentClazz studentClazz = new StudentClazz { Clazz = clazz, Account = account }; _context.Update(studentClazz); } account.RollNumber = "B19APTECH" + account.AccountId.ToString("D4"); account.EncryptPassword(account.Password); _context.Update(account); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountExists(account.AccountId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(account)); }
public UserLogin(IIdentity identity, RoleAccount roles) : base(identity, new string[] { roles.ToString() }) { }