/// <summary> /// Encode password. /// </summary> /// <param name="password">Password.</param> /// <returns>Encoded password.</returns> public byte[] EncodePasswordBytes(string password) { byte[] encodedPassword = ENCODING.GetBytes(password); switch (PasswordFormat) { case MembershipPasswordFormat.Clear: break; case MembershipPasswordFormat.Encrypted: encodedPassword = EncryptPassword(ENCODING.GetBytes(password)); break; case MembershipPasswordFormat.Hashed: using (var context = new TraqnoteEntities()) { encodedPassword = context.GetDigestSHA512(password).FirstOrDefault(); } break; default: throw new ProviderException("Unsupported password format."); } return(encodedPassword); }
public override void CleanUpTestData() { using (var context = new TraqnoteEntities()) { context.Database.ExecuteSqlCommand(@"delete from topic where topic_name = {0}", _topicTestName); } }
public ActionResult Login(Login model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && User.Identity.IsAuthenticated) { //save last login var userinfo = new UserInfo(); var user = userinfo.GetUserSession(); //user. = DateTime.UtcNow; using (var db = new TraqnoteEntities()) { db.Entry(user).State = EntityState.Detached; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } 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)); }
/// <summary> /// Conditionally releases the managed resources directly held by the current instance. /// i.e. The <see cref="TraqnoteEntities"/> used by this service is released, if /// it was instantiated internally by the current instance. /// </summary> /// <remarks> /// The Entity Frameworks objects are likely to refer to some unmanaged resources. It is /// their responsibility to maintain those safely. /// <para> /// The Entity Framework follows the "Unit of Work" pattern. The TraqnoteEntities /// lifespan should be as short as possible. The Dispose() methods allow the consumer to /// have some control over the lifespan of the DbContext. /// </para> /// </remarks> /// <seealso cref="_Context"/> protected virtual void Dispose(bool disposing) { if (this._context != null) { this._context.Dispose(); this._context = null; } }
public override bool ValidateUser(string username, string password) { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { return(false); } using (var dbContext = new TraqnoteEntities()) { var passwordEncoded = EncodePasswordBytes(password); var user = (from us in dbContext.users where string.Compare(username, us.user_name, StringComparison.OrdinalIgnoreCase) == 0 && us.password == passwordEncoded && us.active == true select us).FirstOrDefault(); return(user != null); } }
public void SaveATopic() { _topicTestName = Guid.NewGuid().ToString().Substring(0, 20); var newTopic = new Topics() { Created_On = DateTime.Now, TopicName = _topicTestName }; using (var svc = new TopicServices()) { svc.SaveTopic(newTopic); } using (var db = new TraqnoteEntities()) { Assert.AreEqual(_topicTestName, db.topics.FirstOrDefault(x => x.topic_name == _topicTestName).topic_name); } }
public ActionResult CreateTopic(Topics topics) { if (ModelState.IsValid) { using (var DBContext = new TraqnoteEntities()) { if (DBContext.topics.Any(x => x.topic_name.ToLower() == topics.TopicName.ToLower())) { ModelState.AddModelError("", $"Topic already exists: {topics.TopicName}"); return(View()); } using (var context = new TopicServices()) { context.SaveTopic(topics); } } } // Go to home page after a post has been created return(RedirectToAction("CreatePost", "Post")); }
/// <summary> /// Constructor builds an instance of <see cref="BaseServices"/> and /// populates the <see cref="_Context"/>. /// </summary> /// <remarks> /// Enables constructor based injection of the <see cref="TraqnoteEntities"/> /// which can enable isolated unit testing. /// </remarks> /// <param name="pDbContext">The <see cref="TraqnoteEntities"/> to assign as the /// service's _Context.</param> public BaseServices(TraqnoteEntities pDbContext) { this._context = pDbContext; }
public UserInfo() { _context = new TraqnoteEntities(); }
/// <summary> /// Constructor builds an instance of <see cref="PostServices"/> and /// populates the <see cref="BaseServices.DbContext"/>. /// </summary> /// <remarks> /// Enables constructor based injection of the <see cref="TraqnoteEntities"/> /// which can enable isolated unit testing. /// </remarks> /// <param name="pContext">The <see cref="RolloutManagementContext"/> to assign as the /// <see cref="BaseServices.RmsDbContext"/>.</param> public PostServices(TraqnoteEntities pContext) : base(pContext) { // Intentionally left empty }