public static bool SendMail(string template, PurpleAccount recipient, string placeholder)
    {
        bool result = false;
        string culture = "#";
        if(!string.IsNullOrEmpty(recipient.language_code) && !string.IsNullOrEmpty(recipient.country_code))
            culture = recipient.language_code + "-"+recipient.country_code.ToUpper();
        string body = get_mail_template (template, culture);

        if(!string.IsNullOrEmpty(body))
        {
            string title = extract_title(body);
            body = clean_body(body);

            PurpleMail.ResetDictionary();
            PurpleMail.AddDictionaryEntry("USERNAME",recipient.username);
            PurpleMail.AddDictionaryEntry("FIRST_NAME",recipient.first_name);
            PurpleMail.AddDictionaryEntry("LAST_NAME",recipient.last_name);
            PurpleMail.AddDictionaryEntry("EMAIL",recipient.email);

            string salt = PurpleHash.Token ().Substring(0,5);
            string token = PurpleHash.CalculateSHA(salt + recipient.guid) + ":" +
                            PurpleHash.CalculateSHA(salt + recipient.email) + ":" + salt;
            PurpleMail.AddDictionaryEntry("TOKEN",token);

            if(!string.IsNullOrEmpty(placeholder))
                PurpleMail.AddDictionaryEntry("PLACEHOLDER",placeholder);

            body = clean_gender_specific_data(body, recipient.gender);

            result = PurpleMail.Send (recipient.email, title, body);
            PurpleMail.ResetDictionary();
        }
        return result;
    }
Exemplo n.º 2
0
        public static string GenerateToken(PurpleAccount account, string password_or_token, NetworkPlayer? np = null)
        {
            if(!ValidateAuthentication (account.username, password_or_token))
                return string.Empty;

            account.token = PurpleHash.Token ();
            account.token_created = DateTime.Now;

            if(np != null)
            {
                if(update_user_reference (account, np, true))
                    return account.token;
            }
            else
            {
                if(update_user_reference (account, true))
                    return account.token;
            }
            return string.Empty;
        }
Exemplo n.º 3
0
        private static bool update_user_reference(PurpleAccount user, PurpleNetworkUser pnu, bool authenticated)
        {
            if(pnu != null)
            {
                pnu.UserGUID 			= new Guid(user.guid);
                pnu.UserID 				= user.id;
                pnu.UserType 			= (PurpleNetwork.UserTypes) Enum.Parse(
                                            typeof(PurpleNetwork.UserTypes), user.account_type, true);
                pnu.UserName			= user.username;
                pnu.UserPassword        = user.password;
                pnu.UserToken			= user.token;
                pnu.UserTokenCreated	= user.token_created;

                pnu.UserAuthenticated	= authenticated;
            }
            user.last_seen 				= DateTime.Now;
            return update_database_user (user);
        }
Exemplo n.º 4
0
 private static bool update_user_reference(PurpleAccount user, bool authenticated)
 {
     PurpleNetworkUser pnu = PNS.UserList
         .Find (x => x.UserName == user.username || x.UserGUID.Equals(user.guid));
     return update_user_reference(user, pnu, authenticated);
 }
Exemplo n.º 5
0
 private static bool update_user_reference(PurpleAccount user, NetworkPlayer? np, bool authenticated)
 {
     if(np == null)
         return false;
     PurpleNetworkUser pnu = PNS.UserList
         .Find (x => x.UserReference == np || x.UserName == user.username || x.UserGUID.Equals(user.guid));
     return update_user_reference(user, pnu, authenticated);
 }
Exemplo n.º 6
0
 private static bool update_user_last_seen(PurpleAccount user)
 {
     return SQLGenerator.New ().Update("last_seen = now()", accountTable, "guid="+user.guid).Execute() == 1;
 }
Exemplo n.º 7
0
 private static bool update_database_user(PurpleAccount user)
 {
     if(PurpleAttributes.Validator.Validate (user, out errorList))
     {
         int result = user.ToSQLUpdate ().Execute ();
         return (result==1) ? true : false;
     }
     return false;
 }
Exemplo n.º 8
0
        private static bool create_database_user(PurpleAccount user, string password)
        {
            PurplePassword PuPa = new PurplePassword ();
            user.password = PuPa.CreateHash(password);
            user.NewGuid();
            user.account_created = DateTime.Now;
            user.account_type = "User";
            user.active = false;

            if(PurpleAttributes.Validator.Validate (user, out errorList))
            {
                int result = user.ToSQLInsert ().Execute ();
                if(result == 1)
                    PurpleMailGenerator.SendMail(PurpleConfig.Mail.Template.Register, user);
                return (result==1) ? true : false;
            }
            return false;
        }
Exemplo n.º 9
0
        public static bool Register(PurpleAccount account, string password)
        {
            if(!IsUniqueUsername(account.username))
                return false;

            if (PurpleAccountValidator.ValidatePasswordStrength (password)
                    && PurpleAccountValidator.ValidateUsername (account.username))
            {
                return create_database_user(account, password);
            }
            return false;
        }
Exemplo n.º 10
0
 public static bool SendMail(string template, PurpleAccount recipient)
 {
     return SendMail (template, recipient, string.Empty);
 }