示例#1
0
    private string GetGuidFromUser(User user)
    {
      var begin = user.Email.Replace("@", "-") + "__";
      var file = _dataManager.GetFile(DataFolders.UsersToken, f => f.Name.StartsWith(begin));

      return file.Name.Substring(begin.Length);
    }
示例#2
0
 public void RemoveToken(User user, UserToken token)
 {
   if(token != null)
   {
     var tokenFileName = user.Email.Replace("@", "-") + "__" + token.Guid;
     var tokenIndex = _dataManager.GetFile(DataFolders.UsersToken, tokenFileName).OpenIndex();
     tokenIndex.Remove(i => i.Skip(1).First() == token.Token);
   }
 }
示例#3
0
    public MvcMailMessage PasswordReset(User user, string reseturl)
    {
      ViewBag.Naam = user.Name;
      ViewBag.ResetUrl = reseturl;

      var resources = new Dictionary<string, string>();
      resources["emaillogo"] = EmailLogoPath;

      return Populate(x =>
      {
        x.Subject = "Uw wachtwoord voor dereddingsark.nl";
        x.ViewName = "PasswordReset";
        x.To.Add(new MailAddress(user.Email, user.Name));
        x.From = new MailAddress(Email_AddressTo, Email_Name);
        x.ReplyToList.Add(new MailAddress(Email_AddressReplyTo, Email_Name));
        x.LinkedResources = resources;
      });
    }
示例#4
0
    public UserToken StoreNewToken(User user, string ipaddress)
    {
      var token = Salt();
      var generated = DateTime.UtcNow.ToString("yyyyMMddTHH:mm:ss");
      var guid = GetGuidFromUser(user);

      var tokenFileName = user.Email.Replace("@", "-") + "__" + guid;

      var file = _dataManager.GetFile(DataFolders.UsersToken, tokenFileName);
      file.AppendCsvValues(ipaddress, token, generated);

      return new UserToken
      {
        Generated = generated,
        Token = token,
        Guid = guid,
        IpAddress = ipaddress
      };
    }
示例#5
0
    public void Update(User user, string password)
    {
      string salt = Salt();
      string passwordHash = HashPassword(password, salt);
      var indexLine = string.Format("\"{0}\", \"{1}\", \"{2}\", \"{3}\", \"{4}\"", user.Email, user.Name, passwordHash, salt, user.Extras);

      _userIndex.Update(i => i.First().Equals(user.Email, StringComparison.InvariantCultureIgnoreCase)
                  , indexLine);
    }
示例#6
0
 public bool CheckPassword(User user, string password)
 {
   return user.PasswordHash == HashPassword(password, user.Salt);
 }
示例#7
0
    /// <summary>
    /// Genereer voor de gegeven gebruiker een speciaal, eeuwig durend token.
    /// </summary>
    /// <param name="user"></param>
    /// <returns></returns>
    public ApiToken StoreNewApiToken(User user)
    {
      var token = Salt();
      var generated = DateTime.UtcNow.ToString("yyyyMMddTHH:mm:ss");
      var guid = GetGuidFromUser(user);

      var tokenFileName = user.Email.Replace("@", "-") + "__" + guid;

      var file = _dataManager.GetFile(DataFolders.UsersToken, tokenFileName);
      file.AppendCsvValues("API", token, generated);

      return new ApiToken() { Guid = guid, Token = token };
    }
    public ActionResult Mail(string to, string subject, string body, bool? test)
    {
      if(Request.RequestType == "GET")
      {
        return View();
      }
      else
      {
        var users = Users.GetUsers().ToList();
        if(to == "baarn")
        {
          users = users.Where(u => u.Baarn).ToList();
        }
        else if(to == "bunschoten")
        {
          users = users.Where(u => u.Bunschoten).ToList();
        }
        if(test != null && test.Value)
        {
          users = new User[] { CurrentUser }.ToList();
        }

        string htmlmessage = new Markdown().Transform(body)
          .Replace("<p>", "<p style=\"color: #555; font-size: 15px; margin-top: 20px; padding: 10px;\">")
          .Replace("<a ", "<a style=\"color: #555; font-size: 15px;\" ");

        for(var i = 0; i < users.Count; i = i + 20)
        {
          var batch = users.Skip(i).Take(20);
          try
          {
            Mailer.GroupMail(batch, subject, htmlmessage, body).Send(new SmtpClient().Wrap());
          }
          catch(Exception e)
          {
            Elmah.ErrorLog.GetDefault(System.Web.HttpContext.Current)
              .Log(new Elmah.Error(
                new InvalidOperationException("Fout bij mailen aan " +
                      string.Join(", ", batch.Select(u => u.Email)), e)
               ));
          }
        }

        return RedirectToAction("Mail");
      }
    }
    public UserToken ClearUserToken(User user)
    {
      var cookie = _request.Cookies[Login_Cookie];

      var responsecookie = new HttpCookie(Login_Cookie);
      responsecookie.HttpOnly = true;
      responsecookie.Secure = true;
      responsecookie.Expires = DateTime.Now.AddDays(-1);
      _response.Cookies.Add(responsecookie);

      var httpsResponsecookie = new HttpCookie(Https_Cookie);
      httpsResponsecookie.Value = "0";
      httpsResponsecookie.HttpOnly = true;
      httpsResponsecookie.Expires = DateTime.Now.AddDays(-1);
      _response.Cookies.Add(httpsResponsecookie);

      if(cookie != null)
      {
        var token = cookie.Values["token"];
        var guid = cookie.Values["guid"];
        return new UserToken() { Token = token, Guid = guid };
      }

      return null;
    }