Esempio n. 1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            CodeFirstMembershipProvider provider = new CodeFirstMembershipProvider();

            if (ModelState.IsValid)
            {
                if (provider.ExtendedValidateUser(model.UserName.ToString(), model.Password.ToString()))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                var membership = new CodeFirstMembershipProvider();
                try
                {
                    MembershipCreateStatus status;
                    membership.CreateUser(model.Username, model.Password, model.Email, string.Empty, string.Empty, false, null, out status);
                    if (status == MembershipCreateStatus.Success)
                    {
                        //  EmailManager.SendConfirmationEmail(model.Username);
                        return(RedirectToAction("Confirmation", "Account"));
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 3
0
        public JsonResult Login(string userName, string password)
        {
            var cfMembershipProvides = new CodeFirstMembershipProvider();
            var validateUser         = cfMembershipProvides.ValidateUser(userName, password);

            if (!validateUser)
            {
                return(new JsonResult()
                {
                    Data = new
                    {
                        Success = false
                    }
                });
            }

            FormsAuthentication.SetAuthCookie(userName, true);
            var user = UOW.UsersRepository.GetUser(userName);

            return(new JsonResult()
            {
                Data = new
                {
                    Success = true,
                    Id = user.Id,
                    userName = user.Email,
                }
            });
        }
Esempio n. 4
0
        public JsonResult ChangeUserPassword(User user, string newPassword)
        {
            var result = new JsonResult()
            {
                Data = new
                {
                    success = false,
                    message = "There was an error processing your request."
                }
            };

            var success = 0;

            if (!String.IsNullOrEmpty(user.UserId.ToString()))
            {
                var userToUpdate = Context.Users.FirstOrDefault(x => x.UserId == user.UserId);
                var cfmp         = new CodeFirstMembershipProvider();

                cfmp.ChangePassword(userToUpdate.Username, newPassword);

                success = Context.SaveChanges();
            }

            if (success > 0)
            {
                result.Data = new
                {
                    success = true,
                    message = "Password changed."
                };
            }

            return(result);
        }
Esempio n. 5
0
        public void ChangePassword(Guid userId, String newPassword)
        {
            var userToUpdate = Context.Users.First(x => x.UserId == userId);
            var cfmp         = new CodeFirstMembershipProvider();

            cfmp.ChangePassword(userToUpdate.Username, newPassword);
            Context.SaveChanges();
        }
Esempio n. 6
0
        public void ChangePassword(Guid userId, String newPassword)
        {
            var userToUpdate = Context.Users.First(x => x.UserId == userId);
            var cfmp = new CodeFirstMembershipProvider();

            cfmp.ChangePassword(userToUpdate.Username, newPassword);
            Context.SaveChanges();
        }
Esempio n. 7
0
        public ActionResult TeamLeaderDashBoard()
        {
            CodeFirstMembershipProvider membershipProvider = new CodeFirstMembershipProvider();
            MembershipUser user              = membershipProvider.GetUser(HttpContext.User.Identity.Name, true);
            string         userEmail         = user.Email.ToString();
            int            ContactID         = contactRepository.FindByEmail(userEmail).ContactID;
            int            CurrentUserTeamID = employeeRepository.TeamID(ContactID);

            Session["CurrentUserTeam"] = CurrentUserTeamID;
            return(View());
        }
Esempio n. 8
0
    public static string CreateUserAndAccount(string userName, string password, object propertyValues = null, bool requireConfirmationToken = false)
    {
        CodeFirstMembershipProvider CodeFirstMembership = Membership.Provider as CodeFirstMembershipProvider;

        IDictionary <string, object> values = null;

        if (propertyValues != null)
        {
            values = new RouteValueDictionary(propertyValues);
        }

        return(CodeFirstMembership.CreateUserAndAccount(userName, password, requireConfirmationToken, values));
    }
Esempio n. 9
0
        public ActionResult RegisterUser(StudentTracker.Core.Entities.User objUser)
        {
            StudentContext db          = new StudentContext();
            var            tokenObject = db.RegistrationTokens.Where(t => t.Token == objUser.RegistrationToken).FirstOrDefault();

            objUser.OrganizationId = tokenObject.OrganizationId;
            objUser.MasterId       = tokenObject.CreatedBy;
            CodeFirstMembershipProvider membership = new CodeFirstMembershipProvider();
            var token = membership.CreateAccount(objUser);

            Roles.AddUserToRole(objUser.Username, Enum.GetName(typeof(UserRoles), tokenObject.RoleId));
            EmailHandler.Utilities.SendConfirmationEmail(objUser.Username);
            return(RedirectToAction("Confirmation", "Account"));
        }
Esempio n. 10
0
        public ActionResult AddEmployee(Employee employee, FormCollection col)
        {
            Employee emp = new Employee();

            emp.TeamID          = Convert.ToInt32(col["EmployeeTeam"]);
            emp.EmployeeRole    = col["roles"];
            emp.EmployeeContact = employee.EmployeeContact;
            employeeRepository.InsertOrUpdate(emp);
            employeeRepository.Save();
            string[] roles    = { emp.EmployeeRole };
            string[] username = { employee.EmployeeContact.ContactEmail };
            MembershipCreateStatus      createStatus;
            CodeFirstMembershipProvider provider = new CodeFirstMembershipProvider();

            provider.CreateAccount(username[0], "KStart123", employee.EmployeeContact.ContactEmail, out createStatus);
            CodeFirstRoleProvider roleProvider = new CodeFirstRoleProvider();

            roleProvider.AddUsersToRoles(username, roles);

            return(View("AdminTasks"));
        }
        public ActionResult ClientRegister(ClientRegister form)
        {
            ClientRegister details = new ClientRegister();

            details = form;
            int enqID = Convert.ToInt32(TempData["EnquiryIdClient"]);
            //RegisterModel regMod = new RegisterModel();
            //AccountController accController = new AccountController();
            Enquiry enq = new Enquiry();

            enq = enquiryRepository.Find(enqID);
            //regMod.UserName = enq.Contact.ContactEmail;
            string Password = PasswordGeneration(enq.Contact.ContactName, enq.Contact.MobileNumber);
            //regMod.Email = enq.Contact.ContactEmail;
            //accController.Register(regMod);
            MembershipCreateStatus      createStatus;
            CodeFirstMembershipProvider provider = new CodeFirstMembershipProvider();

            provider.CreateAccount(enq.Contact.ContactEmail, Password, enq.Contact.ContactEmail, out createStatus);
            CodeFirstRoleProvider roleProvider = new CodeFirstRoleProvider();

            if (createStatus == MembershipCreateStatus.Success)
            {
                if (!roleProvider.RoleExists("Client"))
                {
                    roleProvider.CreateRole("Client");
                }

                string[] roles = { "Client" };
                string[] users = { enq.Contact.ContactEmail.ToString() };
                roleProvider.AddUsersToRoles(users, roles);
            }
            details.EnquiryID = Convert.ToInt32(TempData["EnquiryIdClient"]);
            details.ContactID = enq.ContactID; // Please see this--Pankaj
            clientRegisterRepository.InsertOrUpdate(details);
            clientRegisterRepository.Save();
            return(RedirectToAction("Details", new { id = details.EnquiryID }));
        }
Esempio n. 12
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus      createStatus;
                CodeFirstMembershipProvider provider = new CodeFirstMembershipProvider();
                provider.CreateAccount(model.UserName, model.Password, model.Email, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 13
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                var membership = new CodeFirstMembershipProvider();
                try
                {
                    MembershipCreateStatus status;
                    membership.CreateUser(model.Username, model.Password, model.Email, string.Empty, string.Empty, false, null, out status);
                    if (status == MembershipCreateStatus.Success)
                        //  EmailManager.SendConfirmationEmail(model.Username);
                        return RedirectToAction("Confirmation", "Account");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
 public static string GetHash(string password)
 {
     CodeFirstMembershipProvider cfProvider = new CodeFirstMembershipProvider();
         return cfProvider.GetHash(password);
 }
Esempio n. 15
0
 public ActionResult RegisterUser(StudentTracker.Core.Entities.User objUser)
 {
     StudentContext db = new StudentContext();
     var tokenObject = db.RegistrationTokens.Where(t => t.Token == objUser.RegistrationToken).FirstOrDefault();
     objUser.OrganizationId = tokenObject.OrganizationId;
     objUser.MasterId = tokenObject.CreatedBy;
     CodeFirstMembershipProvider membership = new CodeFirstMembershipProvider();
     var token = membership.CreateAccount(objUser);
     Roles.AddUserToRole(objUser.Username, Enum.GetName(typeof(UserRoles), tokenObject.RoleId));
     EmailHandler.Utilities.SendConfirmationEmail(objUser.Username);
     return RedirectToAction("Confirmation", "Account");
 }
Esempio n. 16
0
    public static string CreateAccount(string userName, string password, bool requireConfirmationToken = false)
    {
        CodeFirstMembershipProvider CodeFirstMembership = Membership.Provider as CodeFirstMembershipProvider;

        return(CodeFirstMembership.CreateAccount(userName, password, requireConfirmationToken));
    }
Esempio n. 17
0
        public JsonResult ChangeUserPassword(User user, string newPassword)
        {
            var result = new JsonResult();

            if (!String.IsNullOrEmpty(user.UserId.ToString()))
            {
                using (var context = new DataContext())
                {
                    var userToUpdate = context.Users.FirstOrDefault(x => x.UserId == user.UserId);
                    var cfmp = new CodeFirstMembershipProvider();

                    cfmp.ChangePassword(userToUpdate.Username, newPassword);

                    context.SaveChanges();
                }
            }

            return result;
        }
Esempio n. 18
0
        public JsonResult ChangeUserPassword(User user, string newPassword)
        {
            var result = new JsonResult()
            {
                Data = new
                {
                    success = false,
                    message = "There was an error processing your request."
                }
            };

            var success = 0;
            if (!String.IsNullOrEmpty(user.UserId.ToString()))
            {
                var userToUpdate = Context.Users.FirstOrDefault(x => x.UserId == user.UserId);
                var cfmp = new CodeFirstMembershipProvider();

                cfmp.ChangePassword(userToUpdate.Username, newPassword);

                success = Context.SaveChanges();
            }

            if (success > 0)
            {
                result.Data = new
                {
                    success = true,
                    message = "Password changed."
                };
            }

            return result;
        }