public User CreateForumUser(User user, string activationid) { using (ExternalDbContext db = new ExternalDbContext()) { db.Users.Add(user); db.SaveChanges(); } using (ExternalDbContext db = new ExternalDbContext()) { db.Database.ExecuteSqlCommand("INSERT INTO `vb3_userfield` (userid) VALUES(@userid)", new MySqlParameter("userid", user.userid)); db.SaveChanges(); } using (ExternalDbContext db = new ExternalDbContext()) { db.Database.ExecuteSqlCommand("INSERT INTO `vb3_useractivation` (userid, activationid) VALUES(@userid,@activationid)", new MySqlParameter("userid", user.userid), new MySqlParameter("activationid", activationid)); db.SaveChanges(); } return user; }
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { if (_dataService.IsExistingUsername(username)) { status = MembershipCreateStatus.DuplicateUserName; return null; } if (_dataService.IsExistingEmail(email)) { status = MembershipCreateStatus.DuplicateEmail; return null; } TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)); string salt = SimpleHash.GetSalt(32); string activationCode = ShortGuid.NewGuid(); User user = new User() { email = email, usergroupid = 3, username = username, password = SimpleHash.MD5(password, salt), passworddate = DateTime.Now.Date, usertitle = "Guest", joindate = Convert.ToInt32(ts.TotalSeconds), timezoneoffset = -6, options = 45108439, salt = salt, showbirthday = 0, showvbcode = 0, membergroupids = string.Empty }; user = _dataService.CreateForumUser(user, activationCode); if (user != null) { Login login = new Login(); login.Username = username; login.Password = SimpleHash.MD5(password, salt); login.Email = email; login.ForumUserId = user.userid; login.PasswordSalt = salt; login = _dataService.CreateLogin(login); if (login != null) { NtxfcMembershipProvider provider = Membership.Provider as NtxfcMembershipProvider; provider.SendConfirmationEmail(username, email, String.Format("{0}/Account/Activation/?u={1}&i={2}", ConfigurationManager.AppSettings["MemberUrl"], HttpContext.Current.Server.UrlEncode(username), activationCode)); status = MembershipCreateStatus.Success; return new MembershipUser(this.Name, username, login.Id, login.Email, string.Empty, string.Empty, true, false, new DateTime(), new DateTime(), new DateTime(), new DateTime(), new DateTime()); } } status = MembershipCreateStatus.ProviderError; return null; }