public IHttpActionResult GenerateCode() { string dictionaryString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; StringBuilder resultStringBuilder = new StringBuilder(); var random = new Random(); for (int i = 0; i < 16; i++) { resultStringBuilder.Append(dictionaryString[random.Next(dictionaryString.Length)]); if (i == 3 || i == 7 || i == 11) { resultStringBuilder.Append("-"); } } var result = resultStringBuilder.ToString(); var code = new Code() { Personal_Code = result, Status = "Created", }; db.Codes.Add(code); db.SaveChanges(); return(Ok(code.Personal_Code)); }
public IHttpActionResult Create() { string dictionaryString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; StringBuilder resultStringBuilder = new StringBuilder(); var random = new Random(); for (int i = 0; i < 16; i++) { resultStringBuilder.Append(dictionaryString[random.Next(dictionaryString.Length)]); if (i == 3 || i == 7 || i == 11) { resultStringBuilder.Append("-"); } } var result = resultStringBuilder.ToString(); var code = new Code() { Personal_Code = result, Status = "Created", }; db.Codes.Add(code); db.SaveChanges(); var domain = "http://localhost:3000/checkout"; var options = new SessionCreateOptions { PaymentMethodTypes = new List <string> { "card", }, LineItems = new List <SessionLineItemOptions> { new SessionLineItemOptions { PriceData = new SessionLineItemPriceDataOptions { UnitAmount = 1600, Currency = "eur", ProductData = new SessionLineItemPriceDataProductDataOptions { Name = "Code to access emailing system" } }, Quantity = 1 } }, Mode = "payment", SuccessUrl = domain + "?success=true&code=" + result, CancelUrl = domain + "?success=false" }; var service = new SessionService(); Session session = service.Create(options); return(Ok(session.Id)); }
public IHttpActionResult Register(RegisterUserRequest request) { var code = db.Codes.Where(tempCode => tempCode.Status == "Created").FirstOrDefault(tempCode => tempCode.Personal_Code == request.code); if (code == null) { return(BadRequest()); } bool isEmailValid; try { var addr = new System.Net.Mail.MailAddress(request.email); isEmailValid = addr.Address == request.email; } catch { isEmailValid = false; } if (!isEmailValid || request.password.Length < 5) { return(NotFound()); } var existingUser = db.Users.FirstOrDefault(temp => temp.Email == request.email && temp.Password == request.password); if (existingUser != null) { db.Users.Find(existingUser.Id).Code = code; db.Users.Find(existingUser.Id).SentCount = 0; db.Users.Find(existingUser.Id).Status = "Registered"; db.Codes.Find(code.Id).Status = "Used"; db.Codes.Find(code.Id).User = existingUser; db.SaveChanges(); return(Ok()); } var user = new User() { Email = request.email, Password = request.password, IsAdmin = false, Topic = "This is where your topic goes", Message = "<h1>This is the email's body.</h1><p><br></p><p>You can customize it to your liking.</p>", Status = "Registered", Code = code, SentCount = 0 }; db.Users.Add(user); db.Codes.Find(code.Id).Status = "Used"; db.Codes.Find(code.Id).User = user; db.SaveChanges(); var startupPath = System.Web.Hosting.HostingEnvironment.MapPath("~"); Directory.CreateDirectory(startupPath + "/Uploads/" + user.Id); Directory.CreateDirectory(startupPath + "/Logs/" + user.Id); return(Ok()); }