Exemplo n.º 1
0
 /// <summary>
 /// Notification constructor (create a new one)
 /// </summary>
 /// <param name="title">Notification title</param>
 /// <param name="content">Notification content</param>
 /// <param name="type">Notification type</param>
 public Notification(string title, string content, PermissionType type)
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@title", SqlIntegrate.DataType.NVarChar, title, 50);
     si.AddParameter("@content", SqlIntegrate.DataType.Text, content);
     si.AddParameter("@type", SqlIntegrate.DataType.Int, (int)type);
     si.AddParameter("@UUID", SqlIntegrate.DataType.VarChar, User.Current.UUID);
     Id = Convert.ToInt32(si.Query("INSERT INTO Notification ([title], [content], [type], [UUID]) VALUES (@title, @content, @type, @UUID); SELECT @@IDENTITY"));
     Type = type;
     Title = title;
     Content = content;
     _group = -1;
     if (type == PermissionType.SelfGroupOnly)
         _group = User.Current.Group;
     NotifyTime = DateTime.Now;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Mail constructor
 /// </summary>
 /// <param name="mailId">Mail ID in database</param>
 public Mail(int mailId)
 {
     _mailId = mailId;
     var si = new SqlIntegrate(ConnStr);
     si.AddParameter("@messageid", SqlIntegrate.DataType.Int, mailId);
     var mailInfo = si.Reader("SELECT * FROM hm_messages WHERE messageid = @messageid");
     si.ResetParameter();
     si.AddParameter("@messageid", SqlIntegrate.DataType.Int, mailId);
     Username = si.Query("DECLARE @uid int; SELECT @uid = messageaccountid FROM hm_messages WHERE messageid = @messageid; SELECT accountaddress FROM hm_accounts WHERE accountid = @uid;").ToString().Split('@')[0];
     /* The eml file is storage in this way:
      *
      * When hmailserver receives an email, it writes information in database and stores the eml file.
      *
      * [A] = Hmailserver data path (need to set mailStoragePath in Web.config)
      *
      * [B] = Domain name (SAAO.Mail.mailDomain, need to set mailDomainName in Web.config)
      *
      * [C] = Username (without domain name, "szhang140" for example)
      *
      * [D] = Initial two characters (contain no open brace '{') of eml file name (store in [messagefilename] in database)
      *
      * [E] = Eml file name
      *
      * [F] = [A] \ [B] \ [C] \ [D] \ [E] ("D:\Mail_Data\xuehuo.org\szhang140\1B\{1B961C98-4FC8-40E3-BC8E-FA5A1D374381}.eml" for example)
      *
      * [F] is the absolute path to eml file.
      */
     _emlPath = _mailPath + Username + @"\" + mailInfo["messagefilename"].ToString().Substring(1, 2) + @"\" + mailInfo["messagefilename"];
     _message = ReadEml(_emlPath);
     Flag = (MailFlag)Convert.ToInt32(mailInfo["messageflags"]);
     Subject = _message.Subject;
     // Remove '<' and '>'
     From = new MailAddress(
         name: _message.From.Split('<')[0].Trim(),
         mail: _message.From.Split('<')[1].Replace(">", "").Trim()
     );
     var toCount = _message.To.Trim().Split(',').Length;
     To = new List<MailAddress>();
     for (var i = 0; i < toCount; i++)
         To.Add(new MailAddress(
             name: _message.To.Split(',')[i].Split('<')[0].Trim(),
             mail: _message.To.Split(',')[i].Split('<')[1].Replace(">","").Trim()
         ));
     SentOn = _message.SentOn;
     AttachmentCount = _message.Attachments.Count;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Wechat Login
 /// </summary>
 /// <param name="wechatId">Wechat ID(username)</param>
 /// <returns>Whether the wechat ID has been bound</returns>
 public static bool WechatLogin(string wechatId)
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@wechat", SqlIntegrate.DataType.VarChar, wechatId);
     var r = si.Query(
         "SELECT [username] FROM [User] WHERE [wechat] = @wechat");
     if (r == null) return false;
     Current = new User(r.ToString());
     // TODO: no raw password raw storage!
     return true;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Check whether the user of a username exists and is activated
 /// </summary>
 /// <param name="username"></param>
 /// <returns>Whether the user of a username exists and is activated</returns>
 public static bool Exist(string username)
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@username", SqlIntegrate.DataType.VarChar, username, 50);
     var count = Convert.ToInt32(si.Query("SELECT COUNT(*) FROM [User] WHERE [username] = @username AND [activated] = 1"));
     return count == 1;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Check whether the file has a tag
 /// </summary>
 /// <param name="str">Tag string</param>
 /// <returns>whether the file has this tag</returns>
 public bool HasTag(string str)
 {
     var si = new SqlIntegrate(Utility.ConnStr);
     si.AddParameter("@name", SqlIntegrate.DataType.VarChar, str, 50);
     si.AddParameter("@FUID", SqlIntegrate.DataType.VarChar, _guid);
     var count = Convert.ToInt32(si.Query(
         "SELECT COUNT(*) FROM [Filetag] WHERE [name] = @name AND [FUID] = @FUID"));
     return count != 0;
 }