public ActionResult RecoverPasswordFinish(RecoverPasswordFinishModel model) { if (ModelState.IsValid) { var response = this.VerifyRecaptcha(); if (!response) { return(View(model)); } var accountService = IoCConfig.Service <IAccountService>(); var acc = accountService.GetAccountByIdentity(model.Username); if (!CheckAccount(acc)) { return(View(model)); } //Chưa tồn tại key hoặc key hết hiệu lực if (!acc.Account_RecoverPasswordExpired.HasValue || acc.Account_RecoverPasswordExpired.Value < DateTime.Now) { //reset recover password key acc.Account_RecoverPasswordKey = null; acc.Account_RecoverPasswordExpired = null; accountService.Update(acc); SetCustomError("Mã khôi phục đã hết hiệu lực. Vui lòng thực hiện lại việc khôi phục mật khẩu ở form đăng nhập."); } else if (acc.Account_RecoverPasswordKey != model.RecoverKey) { SetCustomError("Mã khôi phục không đúng. Vui lòng liên hệ lại với ban quản trị."); } if (!ModelState.IsValid) { return(View(model)); } acc.Account_Password = PasswordEncryptManager.EncryptPassword(model.NewPassword); //reset recover password key acc.Account_RecoverPasswordKey = null; acc.Account_RecoverPasswordExpired = null; acc = accountService.Update(acc); if (acc != null) { ViewBag.CurrentStep = 2; SetSuccess("Khôi phục mật khẩu thành công. Hãy click vào Đăng nhập để bắt đầu sử dụng :)"); } else { SetCustomError("Có lỗi xảy ra. Vui lòng thực hiện lại"); } } return(View(model)); }
private User_Profile AddUserProfileToDB(User_Profile user) { var service = IoCConfig.Service <IUserProfileService>(); //Check exist by phone var existed = service.FindValidByCriteria( a => a.User_Profile_Phone != null && a.User_Profile_Phone.Equals(user.User_Profile_Phone) && a.User_Profile_Name != null && a.User_Profile_Name.Equals(user.User_Profile_Name) && a.Id != user.Id); if (existed != null) { SetCustomError("Thông tin tài khoản không tồn tại hoặc bị trùng tên và số điện thoại!"); return(null);//Trung phone va trung name thi khong cho add/edit } if (user.Id != 0)//Edit { user = service.Update(user); //update Account by User Profile IoCConfig.Service <IAccountService>().UpdateAccount(user); } else//Add { //add user user = service.Add(user); //add account var accountService = IoCConfig.Service <IAccountService>(); var account = accountService.Create(user.Email, PasswordEncryptManager.EncryptPassword(AppSettings.DefaultPassword), user.Obj_Id, user); account.HasSetPassword = true; account.Status = user.Status; //Add new account account = accountService.Add(account); if (account != null) { //accountService.Active(account); //GetService().Active(u);//user profile khi add đã active sẵn rồi //start sending email //EmailHelper.SendMail_RegisterActiveSuccess(this.ControllerContext, account); //EmailHelper.SendMail_InformUser(this.ControllerContext, user); //end sending email } } return(user); }
/// <summary> /// RegisterUser/LoginFacebook /// </summary> /// <param name="type"></param> /// <param name="hasAlreadyVerified">Nếu true thì set verified status là true trong hàm ToModel</param> /// <param name="hasAlreadyActive">False: RegisterUser, True: LoginFacebook</param> /// <returns></returns> private Account Create(ControllerContext ctx, U u, bool hasAlreadyActive = false, bool HasSetPassword = true) { u = GetService().Add(u); if (u != null) { var accountService = IoCConfig.Service <IAccountService>(); //Create new Account //- Account_Status = Inactive //- Active Key được new Guid và được gửi về email sau var account = accountService.Create(register.Username, PasswordEncryptManager.EncryptPassword(register.Password), u.Obj_Id, u); account.HasSetPassword = HasSetPassword; //Add new account account = accountService.Add(account); if (account != null) { if (hasAlreadyActive) { accountService.Active(account); //GetService().Active(u);//user profile khi add đã active sẵn rồi //start sending email EmailHelper.SendMail_RegisterActiveSuccess(ctx, account); //end sending email } else { //start sending email EmailHelper.SendMail_RegisterInform(ctx, account); //end sending email } return(account); } } ModelState.AddModelError("CustomError", "Thêm tài khoản thất bại!"); return(null); }
public ActionResult ChangePassword(ChangePasswordModel register) { if (ModelState.IsValid) { //var id = XT.Web.External.AuthenticationManager.Id; var accountService = IoCConfig.Service <IAccountService>(); Account acc = null; if (XT.Web.External.AuthenticationManager.Account_HasSetPassword) { acc = PasswordEncryptManager.Login(XT.Web.External.AuthenticationManager.Account_Username, register.OldPassword); } else { acc = accountService.FindById(XT.Web.External.AuthenticationManager.Id); } if (!CheckAccount(acc)) { return(View(register)); } acc.Account_Password = PasswordEncryptManager.EncryptPassword(register.NewPassword); acc.HasSetPassword = true; acc = accountService.Update(acc); if (acc != null) { SetLoginAuthentication(acc); SetSuccess("Thay đổi mật khẩu thành công!"); } else { SetCustomError("Thay đổi thất bại! Vui lòng thực hiện lại"); } } return(View(register)); }
//public ActionResult Index() //{ // return View(); //} public ActionResult Setup() { /////////////////////////////////////////////////// var CURRENT_COMPANY = 3;//3: AMMHCM //reset HCM feeplans (DeleteForever) //var hcms_ins = IoCConfig.Service<IStudent_FeePlan_InstallmentService>() // .FindAllByCriteria(f => f.Student_FeePlan.Student.Class.Company_Id == CURRENT_COMPANY); //foreach (var ins in hcms_ins) //{ // IoCConfig.Service<IStudent_FeePlan_InstallmentService>().DeleteForever(ins); //} //var hcms = IoCConfig.Service<IStudent_FeePlanService>() // .FindAllByCriteria(f => f.Student.Class.Company_Id == CURRENT_COMPANY); //foreach (var f in hcms) //{ // IoCConfig.Service<IStudent_FeePlanService>().DeleteForever(f); //} //reset HCM schedule //var slist = IoCConfig.Service<IClass_ModuleService>() // .FindAllByCriteria(f => f.Class.Company_Id == CURRENT_COMPANY); //foreach (var ins in slist) //{ // ins.Resource_LT_Id = 1; // ins.Resource_TH_Id = 1; // ins.Resource_Exam_Id = 1; // IoCConfig.Service<IClass_ModuleService>().Update(ins); //} ////reset HCM resource //var rlist = IoCConfig.Service<IResourceService>() // .FindAllByCriteria(f => f.Company_Id == CURRENT_COMPANY); //foreach (var ins in rlist) //{ // IoCConfig.Service<IResourceService>().DeleteForever(ins); //} /////////////////////////////////////////////////// if (AppSettings.GenerateSampleData) { ////////////////////////////////////////////////////////////////////////////////////////// //Truoc khi chay setup phai chay create database script (LinkHouse_Test_Create.sql) ////////////////////////////////////////////////////////////////////////////////////////// //ROLE ENUMS var role_service = IoCConfig.Service <IRole_TypeService>(); if (role_service.FindAll().Count() == 0) { //ROLE TYPE var account_types = new List <Role_Type>(); foreach (RoleTypeEnum type in Enum.GetValues(typeof(RoleTypeEnum))) { account_types.Add(new Role_Type { Id = (int)type, Role_Type_Name = type.ToString(), Created_Date = DateTime.Now }); } role_service.AddAll(account_types.ToArray()); } //USER ENUMS var user_service = IoCConfig.Service <IUser_TypeService>(); if (user_service.FindAll().Count() == 0) { //ROLE TYPE var account_types = new List <User_Type>(); foreach (UserTypeEnum type in Enum.GetValues(typeof(UserTypeEnum))) { account_types.Add(new User_Type { Id = (int)type, User_Type_Name = type.ToString(), Created_Date = DateTime.Now }); } user_service.AddAll(account_types.ToArray()); } var website = AppSettings.Website; //USER_PROFILE var user = new User_Profile { User_Profile_Name = "admin", User_Profile_Email = "admin@" + website, User_Profile_Avatar = "~/Images/default_avatar.jpg", User_Profile_Phone = "0909123456", Status = (int)EntityStatus.Visible, Created_Date = DateTime.Now, Role_Type_Id = (int)RoleTypeEnum.Admin, User_Type_Id = (int)UserTypeEnum.CH, }; user = IoCConfig.Service <IUserProfileService>().Add(user); //ACCOUNT var admin = new Account { User_Profile_Id = user.Id, Account_Username = "******", Account_Name = user.User_Profile_Name, Account_Email = user.User_Profile_Email, Account_Avatar = user.User_Profile_Avatar, Account_Password = PasswordEncryptManager.EncryptPassword("@1234567"), Status = (int)EntityStatus.Visible, Created_Date = DateTime.Now, HasSetPassword = true, }; IoCConfig.Service <IAccountService>().AddAll(new[] { admin }); } return(View()); }