Ejemplo n.º 1
0
 public SpamModule()
     : base("api/spam")
 {
     this.Post["/", true] = (_, cancel) =>
     {
         return Task.Run<dynamic>(() =>
         {
             var file = this.Request.Files.FirstOrDefault();
             string data;
             using (StreamReader sr = new StreamReader(file.Value))
             {
                 data = sr.ReadToEnd();
             }
             string username = this.Context.CurrentUser.UserName;
             bool isValid = IsValidSpamUser(username);
             var db = new CouchDBService();
             var tokens = new TokenService(db);
             string subject = this.Request.Form.subject;
             string body = this.Request.Form.body;
             foreach (var email in GetValidEmails(data, username, isValid))
             {
                 var modBody = InsertLink(body, email, tokens);
                 MailgunService.SendMail(email, subject, modBody);
             }
             return HttpStatusCode.OK;
         });
     };
 }
Ejemplo n.º 2
0
 private string InsertLink(string body, string email, TokenService tokens)
 {
     if (body.IndexOf("!!link!!") != -1)
     {
         var token = tokens.Login(email);
         var combine = string.Format("{0}!{1}", email, token);
         var link = string.Format(@"<a href=""{0}/#/?token={1}"">your secret key</a>", this.Request.Url.SiteBase, combine);
         return body.Replace("!!link!!", link) + "<br><br> Sent on behalf of " + email;
     }
     return body;
 }
Ejemplo n.º 3
0
        public LoginModule()
            : base("/api/login")
        {
            var db = new CouchDB.CouchDBService();
            var tokenService = new TokenService(db);

            Post["/"] = ctx =>
            {
                string username;
                var dto = this.Bind<LoginRequestDto>();
                username = dto.Username;
                var validationResponse = ValidateUsername(username);
                if (validationResponse != null) return validationResponse;
                var token = tokenService.Login(username);
                var combine = string.Format("{0}!{1}", username, token);
                MailgunService.SendMail(username, "The unicorn says hi!", string.Format(File.ReadAllText(Path.Combine(AssemblyDirectory, "Mailing\\LoginMailResponse.txt")), this.Request.Url.SiteBase, combine));
                return HttpStatusCode.OK;
            };
        }
Ejemplo n.º 4
0
 private void init()
 {
     db = new CouchDBService();
     tokenService = new TokenService(db);
 }