public object Post(ActivateUserRequest req) { using (var db = DbConfig.GetConnection()) { var user = db.First <DBUser> (u => u.Username == req.Username); user.IsActivated = true; db.Save(user); } return(new HttpResult() { StatusCode = HttpStatusCode.Created }); }
/// <summary> /// Activate the user /// </summary> /// <param name="userName"></param> /// <param name="token"></param> /// <returns></returns> public virtual ActionResult Activate(string userName, string token) { var activateUserRequest = new ActivateUserRequest() { UserName = userName, Token = token, CurrentUser = DomainSessionService.Instance.CurrentUser, HttpResponse = Response }; var activateUserResponse = _service.ActivateUser(activateUserRequest); return(RedirectToAction(activateUserResponse.IsSuccessful ? MVC.Home.Index() : MVC.Authentication.Login.Index())); }
public ActivateUserResponse ActivateUser(ActivateUserRequest request) { using (var db = new DotWEntities()) { var user = db.Users.FirstOrDefault(x => x.Id == request.Id); if (user != null) { user.ActivationDate = null; user.IdState = (int)UserAccountStates.Active; db.SaveChanges(); } return(new ActivateUserResponse()); } }
public async Task ActivateUserRequestHandler_Handle_Returns_TokenExpired() { AuthenticationContext.OpenInMemoryConnection(); try { using (var context = AuthenticationContext.GetInMemoryContext()) { context.Users.Add(new User { Id = Guid.NewGuid(), Name = "John Doe", ActivationToken = "testtoken", ActivationTokenExpirationDate = DateTime.UtcNow.Subtract(TimeSpan.FromDays(1)) }); context.SaveChanges(); } ActivateUserResponse response; var request = new ActivateUserRequest { ActivationToken = "testtoken" }; using (var context = AuthenticationContext.GetInMemoryContext()) { var handler = new ActivateUserRequestHandler(context); response = await handler.Handle(request); } using (var context = AuthenticationContext.GetInMemoryContext()) { Assert.IsFalse(context.Users.Single().IsActive); Assert.AreEqual(ErrorType.TokenExpired, response.ErrorType); Assert.IsFalse(response.IsSuccess); } } finally { AuthenticationContext.CloseInMemoryConnection(); } }
public async Task ActivateUserRequestHandler_Handle_Returns_Success() { AuthenticationContext.OpenInMemoryConnection(); try { using (var context = AuthenticationContext.GetInMemoryContext()) { context.Users.Add(new User { Id = Guid.NewGuid(), Name = "John Doe", ActivationToken = "token", ActivationTokenExpirationDate = DateTime.UtcNow.AddDays(1) }); context.SaveChanges(); } ActivateUserResponse response; var request = new ActivateUserRequest { ActivationToken = "token" }; using (var context = AuthenticationContext.GetInMemoryContext()) { var handler = new ActivateUserRequestHandler(context); response = await handler.Handle(request); } using (var context = AuthenticationContext.GetInMemoryContext()) { Assert.IsTrue(context.Users.Single().IsActive); Assert.IsNull(context.Users.Single().ActivationToken); Assert.IsTrue(response.IsSuccess); } } finally { AuthenticationContext.CloseInMemoryConnection(); } }
public ResponseDto ActivateUser(ActivateUserRequest request) { ResponseDto response = new ResponseDto(); Consumer consumer = null; try { using (UserDao userDao = new UserDao()) { consumer = GetAuthUser(userDao, request.user_id, request.auth_token); if (consumer == null) { MakeNouserResponse(response); return(response); } if (consumer.ConsActivated) { response.code = 0; response.has_resource = 0; response.message = MessagesSource.GetMessage("user.active"); return(response); } bool validOtp = OTPServices.ValidateOTP(request.user_id, request.otp_code); if (validOtp) { consumer.ConsActivated = true; userDao.Update(consumer); response.code = 0; response.has_resource = 0; response.message = MessagesSource.GetMessage("user.activated"); } return(response); } } catch (Exception ex) { response.MakeExceptionResponse(ex); return(response); } }
public object Post(ActivateUserRequest req) { using (var db = DbConfig.GetConnection ()) { var user = db.First<DBUser> (u => u.Username == req.Username); user.IsActivated = true; db.Save (user); } return new HttpResult () { StatusCode = HttpStatusCode.Created }; }
//public static void CopyToEntity(Consumer consumer, ResendOtpRequest request) //{ // consumer.ConsID = request.user_id; // consumer.AccToken = request.auth_token; // consumer.IMEI = request.imei; //} /* * public static void CopyFromEntity(ResendOtpResponse response, Consumer consumer) * { * response.otp_details.send_otp = consumer.; * } */ public static void CopyToEntity(Consumer consumer, ActivateUserRequest request) { consumer.ConsID = request.user_id; consumer.AccToken = request.auth_token; consumer.IMEI = request.imei; }
public NegotiatedContentResult <ResponseDto> PostActivateUser([FromBody] ActivateUserRequest request) { ResponseDto resp = _userServices.ActivateUser(request); return(Content(HttpStatusCode.OK, resp)); }