public ActionResult Register(UserRegistrationVM model) { if (ModelState.IsValid) { //var hashedPassword = Crypto.HashPassword(model.Password); var hashed = Assigment.HashClass.Encode(model.Password); var db = new MyDBEntities(); var admin = 0; if (Session["isAdmin"] != null) { if ((int)Session["isAdmin"] == 1) { admin = 1; } } db.users.Add(new user { Firstname = model.Firstname, Surname = model.Surname, Username = model.Username, EmailAddress = model.EmailAddress, Password = hashed, isAdmin = admin }); db.SaveChanges(); return(RedirectToAction("Login", "User")); } return(View(model)); }
public ActionResult Update() { var db = new MyDBEntities(); UserRegistrationVM vmodel = new UserRegistrationVM(); if (Session["LoggedIn"] != null) { if (Session["id"] == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var userToUpdate = db.users.Find((int)Session["id"]); vmodel.Id = ((int)Session["id"]); vmodel.Firstname = userToUpdate.Firstname; vmodel.Surname = userToUpdate.Surname; vmodel.Username = userToUpdate.Username; vmodel.Password = userToUpdate.Password; vmodel.EmailAddress = userToUpdate.EmailAddress; } else { Response.Redirect("../User/Login"); //making sure you substitute “Login” for whatever your login method is actually called if different } return(View(vmodel)); }
public ActionResult Register(UserRegistrationVM userRegistration) { if (ModelState.IsValid) { Manager um = new Manager(); ReaderWriterLock locker = UsernamesChecks.GetUsernamesChecksReaderWriterLocker(HttpContext.Application); try { locker.AcquireWriterLock(-1); try { if (UsernamesChecks.IsUsernameReserved(HttpContext.Application, Session, userRegistration.Username)) { throw new InvalidOperationException("The selected username already exists"); } um.SaveNewUser(userRegistration.GetUser()); UsernamesChecks.ReleaseUsernameFromReservedUsernamesCollection(HttpContext.Application, Session, userRegistration.Username); TempData["succesfulRegistration"] = true; return(RedirectToAction("Login")); } finally { locker.ReleaseWriterLock(); } } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); } } return(View(userRegistration)); }
public ActionResult Update(UserRegistrationVM model) { if (Session["LoggedIn"] != null) { var db = new MyDBEntities(); var userToUpdate = db.users.Find((int)Session["id"]); var hashed = Assigment.HashClass.Encode(model.Password); if (ModelState.IsValid) { if (userToUpdate != null) { userToUpdate.Id = (int)Session["id"]; userToUpdate.Firstname = model.Firstname; userToUpdate.Surname = model.Surname; userToUpdate.Username = model.Username; userToUpdate.Password = hashed; userToUpdate.EmailAddress = model.EmailAddress; db.SaveChanges(); } } ViewData["Message"] = "Record updated"; } else { Response.Redirect("../User/Login"); //making sure you substitute “Login” for whatever your login method is actually called if different } return(View(model)); }
public ActionResult Login(UserRegistrationVM UR) { if (string.IsNullOrEmpty(UR.UserName) || string.IsNullOrEmpty(UR.UserName)) { ViewBag.ErrorMessage = "Please fill mandatory fields"; return(View()); } var password = UR.Encrypt(UR.Password); var output = _db.tblusers.FirstOrDefault(obj => obj.username == UR.UserName && obj.passwordHash == password && obj.role_id.Value != 2); if (output != null) { FormsAuthentication.SetAuthCookie(UR.UserName, true); Session["UserName"] = UR.UserName.ToUpper(); return(RedirectToAction("Home", "Home")); } else { ViewBag.ErrorMessage = "Invalid Credentials!"; return(View()); } }
public async Task <IActionResult> Register([FromBody] UserRegistrationVM model) { try { if (ModelState.IsValid) { ApplicationUser user = await UserManager.FindByNameAsync(model.Email); if (user == null) { user = new ApplicationUser(); user.Email = model.Email; user.FirstName = model.FirstName; user.FamilyName = model.FamilyName; user.UserName = model.Email; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { return(Ok()); } } } return(BadRequest()); } catch (Exception ex) { throw new Exception(ex.Message); } }
public ActionResult Login() { tbluser u = new tbluser(); // tbluser objUserRegistrationVM = new tbluser(); UserRegistrationVM objUserRegistrationVM = new UserRegistrationVM(); return(View(objUserRegistrationVM)); }
public ActionResult Signout() { FormsAuthentication.SignOut(); Session.Clear(); UserRegistrationVM objUserRegistrationVM = new UserRegistrationVM(); //tbluser objUserRegistrationVM = new tbluser(); return(View("Login", objUserRegistrationVM)); }
public async Task <IActionResult> Edit(UserRegistrationVM data) { try { var user = _userManger.Users.FirstOrDefault(x => x.Id == data.Id); user.FirstName = data.FirstName; user.LastName = data.LastName; user.Email = data.Email; user.UserName = data.Email; user.PhoneNumber = data.PhoneNumber; user.LockoutEnabled = data.LockoutEnabled; //var user = new AppUser //{ // Id=data.Id, // UserName = data.Email, // Email = data.Email, // FirstName = data.FirstName, // LastName = data.LastName, // EmailConfirmed = true, // PhoneNumberConfirmed = true //}; IdentityResult result = await _userManger.UpdateAsync(user); if (result.Succeeded) { return(Json(new { type = "success", title = "successfully", message = "Done!", id = user.Id })); } else { return(Json(new { type = "error", title = "successfully", message = "Done!" })); } } catch (Exception e) { return(Json(new { type = "error", title = "Some error occured", message = e.ToString() })); } }
public async Task <IHttpActionResult> Register(UserRegistrationVM userRegistrationVM) { var result = await _authDalHelper.RegisterUser(_mapper.Map <UserEntity>(userRegistrationVM)); if (!result.Succeeded) { throw new InvalidInputException("User registration error", result.Errors); } return(Ok()); }
public void Register(UserRegistrationVM user) { User newUser = new User() { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, EmailActivated = false, Password = user.Password, ListOfProjects = new List <Project>() }; Add(newUser); }
public ActionResult Create(UserRegistrationVM userRegVm) { if (ModelState.IsValid) { User user = new User(); user.Id = userRegVm.Id; user.Name = userRegVm.Name; user.Email = userRegVm.Email; user.DOB = userRegVm.DOB; user.Password = userRegVm.ConfirmPassword; db.User.Add(user); db.SaveChanges(); return(RedirectToAction("Create")); } return(View(userRegVm)); }
//public async Task<ApiResponse> CreateUpdate(UserRegistrationVM _vmEmployee) public async Task <IHttpActionResult> CreateUpdate(UserRegistrationVM _vmEmployee) { ApiResponse apiResponse = new ApiResponse(); _IuserRegistration = new UserRegisterRepo(); try { //Int32 Result = await _IuserRegistration.CreateUpdate(_vmEmployee); //return new ApiResponse { IsValidUser = true, Message = string.Empty, MessageType = Result }; IHttpActionResult objResult = await _IuserRegistration.CreateUpdate(_vmEmployee); return(objResult); } catch (Exception ex) { apiResponse = TaskUTL.GenerateExceptionResponse(ex, _pageName, true); return(null); } }
public ActionResult Edit(UserRegistrationVM v) { UserRegistration a = new UserRegistration(); a.UserID = v.UserID; a.UserName = v.UserName; a.Password = v.Password; a.RoleID = v.RoleID; a.Phone = v.Phone; a.EmailId = v.EmailId; a.IsActive = v.IsActive; if (ModelState.IsValid) { db.Entry(a).State = EntityState.Modified; db.SaveChanges(); TempData["SuccessMsg"] = "You have successfully Updated User."; return(RedirectToAction("Index")); } return(View()); }
public async Task <IActionResult> Register(UserRegistrationVM data) { if (ModelState.IsValid) { try { var user = new AppUser { UserName = data.Email, Email = data.Email, FirstName = data.FirstName, LastName = data.LastName, EmailConfirmed = true, PhoneNumberConfirmed = true }; var result = await _userManger.CreateAsync(user, data.Password); if (result.Succeeded) { return(Json(new { type = "success", title = "successfully", message = "Done!", id = user.Id })); } } catch (Exception e) { return(Json(new { type = "Error", title = "Some error occured", message = e.ToString() })); } } return(PartialView(data)); }
public ActionResult Edit(int id) { ViewBag.UserRole = db.RoleMasters.ToList(); UserRegistrationVM v = new UserRegistrationVM(); var a = (from c in db.UserRegistrations where c.UserID == id select c).FirstOrDefault(); if (a == null) { return(HttpNotFound()); } else { v.UserID = a.UserID; v.UserName = a.UserName; v.Phone = a.Phone; v.EmailId = a.EmailId; v.RoleID = a.RoleID.Value; v.Password = a.Password; v.IsActive = a.IsActive.Value; } return(View(v)); }
public async Task <IActionResult> Registration(UserRegistrationVM registrationVM) { if (db.users.Any(u => u.login == registrationVM.login)) { ModelState.AddModelError(nameof(registrationVM.login), "This login is already in use"); } if (registrationVM.email != null && db.users.Any(u => u.email == registrationVM.email)) { ModelState.AddModelError(nameof(registrationVM.email), "This email is already in use"); } if (registrationVM.password != registrationVM.confirmPassword) { ModelState.AddModelError(nameof(registrationVM.password), "Passwords are not same"); } if (ModelState.IsValid) { UserModel user = registrationVM.GetDbModel(); db.users.Add(user); db.SaveChanges(); await Authenticate(user.login); HttpContext.Session.SetString("login", user.login); var session = HttpContext.Session.SessionInfo(); resultBuilder.AddJSFuncModel("updateUserInfo", session); resultBuilder.AddJSFuncInline("reloadHubConnection"); return(Json(resultBuilder.Build())); } else { resultBuilder.AddAspView(this, "Registration", registrationVM); return(Json(resultBuilder.Build())); } }
public ActionResult RegisterUser(UserRegistrationVM newUser) { string registrationMessage = null; if (ModelState.IsValid) { try { service.Register(newUser); registrationMessage = "Na podany adres e-mail została wysłana wiadomość weryfikacjyjna."; MailSender.BuildRegistrationEmailTemlplate(newUser.Email); return(RedirectToAction("Index", "Home", new { message = registrationMessage })); } catch (Exception) { registrationMessage = "Istnieje już konto o podanym adresie e-mail."; return(RedirectToAction("Index", "Home", new { message = registrationMessage })); } } else { return(View("../Home/Index")); } }
public ActionResult Create(UserRegistrationVM v) { if (v.UserID == 0) { string status = "true"; UserRegistration x = (from b in db.UserRegistrations where b.UserName == v.EmailId select b).FirstOrDefault(); if (x != null) { TempData["ErrorMsg"] = "Email Id already exist!"; ViewBag.UserRole = db.RoleMasters.ToList(); return(View(v)); } UserRegistration a = new UserRegistration(); int max = (from c in db.UserRegistrations orderby c.UserID descending select c.UserID).FirstOrDefault(); a.UserID = max + 1; a.UserName = v.EmailId; a.Password = v.Password; a.RoleID = v.RoleID; a.Phone = ""; a.EmailId = v.EmailId; a.IsActive = v.IsActive; db.UserRegistrations.Add(a); db.SaveChanges(); if (a.RoleID == 13) //customer { var customer = db.CustomerMasters.Find(v.UserReferenceId); if (customer != null) { customer.UserID = a.UserID; db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); } } else if (a.RoleID == 14) //AGent { var agent = db.AgentMasters.Find(v.UserReferenceId); if (agent != null) { agent.UserID = a.UserID; db.Entry(agent).State = EntityState.Modified; db.SaveChanges(); } } else { var employee = db.EmployeeMasters.Find(v.UserReferenceId); if (employee != null) { employee.UserID = a.UserID; db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); } } if (v.EmailNotify == true) { EmailDAO _emaildao = new EmailDAO(); _emaildao.SendCustomerEmail(v.EmailId, v.UserName, v.Password); TempData["SuccessMsg"] = "You have successfully added User and Notification Mail has sent!"; } else { TempData["SuccessMsg"] = "You have successfully added User."; } } else { //UserRegistration uv = db.UserRegistrations.Find(v.UserID); var uv = db.UserRegistrations.Find(v.UserID);// (from c in db.UserRegistrations where c.UserID == v.UserID select c).FirstOrDefault(); //UserRegistration a = new UserRegistration(); //a.UserID = v.UserID; uv.UserName = v.EmailId; if (v.Password != null) { if (v.Password != uv.Password) { uv.Password = v.Password; } } //uv.RoleID = v.RoleID; uv.EmailId = v.EmailId; uv.IsActive = v.IsActive; db.Entry(uv).State = EntityState.Modified; db.SaveChanges(); if (uv.RoleID == 13) //customer { var customer = db.CustomerMasters.Find(v.UserReferenceId); if (customer != null) { customer.UserID = uv.UserID; db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); } } else if (uv.RoleID == 14) //AGent { var agent = db.AgentMasters.Find(v.UserReferenceId); if (agent != null) { agent.UserID = uv.UserID; db.Entry(agent).State = EntityState.Modified; db.SaveChanges(); } } else { var employee = db.EmployeeMasters.Find(v.UserReferenceId); if (employee != null) { employee.UserID = uv.UserID; db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); } } if (v.EmailNotify == true) { EmailDAO _emaildao = new EmailDAO(); _emaildao.SendCustomerEmail(v.EmailId, v.UserName, v.Password); TempData["SuccessMsg"] = "You have successfully Updated User Detail and Notification Mail has sent."; } else { TempData["SuccessMsg"] = "You have successfully Updated User."; } } return(RedirectToAction("Index")); }
public ActionResult Create(int id = 0) { ViewBag.UserRole = db.RoleMasters.ToList(); UserRegistrationVM v = new UserRegistrationVM(); if (id == 0) { v.UserID = 0; v.IsActive = true; ViewBag.EditMode = "false"; ViewBag.Title = "User - Create"; return(View(v)); } else { ViewBag.Title = "User - Modify"; var a = (from c in db.UserRegistrations where c.UserID == id select c).FirstOrDefault(); if (a == null) { return(HttpNotFound()); } else { v.UserID = a.UserID; v.RoleID = a.RoleID.Value; v.EmailId = a.EmailId; if (v.RoleID == 13) { var User = db.CustomerMasters.Where(cc => cc.UserID == v.UserID).FirstOrDefault(); if (User != null) { v.UserName = User.CustomerName; v.UserReferenceId = User.CustomerID; } else { v.UserName = ""; v.UserReferenceId = 0; } } else if (v.RoleID == 14) { var agent = db.AgentMasters.Where(cc => cc.UserID == v.UserID).FirstOrDefault(); if (agent != null) { v.UserName = agent.Name; v.UserReferenceId = agent.AgentID; } else { v.UserName = ""; v.UserReferenceId = 0; } } else { var employee = db.EmployeeMasters.Where(cc => cc.UserID == v.UserID).FirstOrDefault(); if (employee != null) { v.UserName = employee.EmployeeName; v.UserReferenceId = employee.EmployeeID; } else { v.UserName = ""; v.UserReferenceId = 0; } } v.Password = a.Password; v.IsActive = a.IsActive.Value; ViewBag.EditMode = "true"; return(View(v)); } } }
public async Task <IHttpActionResult> CreateUpdate(UserRegistrationVM objEmployee) { try { using (SqlCommand dataCmd = new SqlCommand("UserRegistration", objCommonDB.con)) { dataCmd.CommandType = CommandType.StoredProcedure; //dataCmd.Parameters.AddWithValue("@UserID", objEmployee._userId); //dataCmd.Parameters["@UserID"].Direction = ParameterDirection.InputOutput; dataCmd.Parameters.Add(new SqlParameter("@UserName", objEmployee._userName)); dataCmd.Parameters.Add(new SqlParameter("@FirstName", objEmployee._firstName)); dataCmd.Parameters.Add(new SqlParameter("@LastName", objEmployee._lastName)); dataCmd.Parameters.Add(new SqlParameter("@Password", objEmployee._password)); dataCmd.Parameters.Add(new SqlParameter("@Phone", objEmployee._phone)); dataCmd.Parameters.Add(new SqlParameter("@EmailId", objEmployee._emailId)); dataCmd.Parameters.Add(new SqlParameter("@City", objEmployee._city)); dataCmd.Parameters.Add(new SqlParameter("@State", objEmployee._state)); if (objCommonDB.con.State == ConnectionState.Closed) { objCommonDB.con.Open(); } //await dataCmd.ExecuteNonQueryAsync(); var reader = await dataCmd.ExecuteReaderAsync(); //return Convert.ToInt32(dataCmd.Parameters["@UserID"].Value); UserRegistrationResp objUser = new UserRegistrationResp(); while (reader.Read()) { objUser.ResultType = Convert.ToInt16(reader["ResultType"].ToString()); objUser.UpdateUrl = reader["UpdateUrl"].ToString(); objUser.Result = reader["Result"].ToString(); } var multiFileContent = new MultipartContent(); if (objUser.ResultType == 1) { //string[] _arrExe = objUserupdate.FileName.Split(','); //List<string> list = new List<string>(_arrExe); //var fileNames = new List<string>(_arrExe); //var objectContent = new ObjectContent<List<string>>(fileNames, new System.Net.Http.Formatting.JsonMediaTypeFormatter()); //multiFileContent.Add(objectContent); string fileName = "Setup.msi"; //var fullPath = objUser.UpdateUrl + "" + fileName ; var fullPath = @"E:\demo_repo\Bhavesh\LockDown-15-04-2020\" + fileName; var fileBytes = File.ReadAllBytes(fullPath); //for (int i = 0; i < fileNames.Count ; i++) //{ // string fileName = fileNames[i].ToString(); // var filePath = objUserupdate.UpdateUrl + fileName; //client = new WebClient(); //byte[] fileBytes = client.DownloadData((new Uri(filePath))); var fileMemoryStream = new MemoryStream(fileBytes); var fileContent = new StreamContent(fileMemoryStream); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); fileContent.Headers.ContentDisposition.FileName = fileName; fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); fileContent.Headers.ContentLength = fileMemoryStream.Length; multiFileContent.Add(fileContent); return(new ApiFileResult(fileMemoryStream, "application/octet-stream", $"Billing Export {DateTime.Today:yyyy-MM-dd}{fileName}")); //} } var response = new HttpResponseMessage(HttpStatusCode.OK); response.Headers.Add("objUser", new JavaScriptSerializer().Serialize(objUser)); response.Content = multiFileContent; return(null); } } catch (Exception ex) { throw; } finally { if (objCommonDB.con.State == ConnectionState.Open) { objCommonDB.con.Close(); } } }