public static string GetSiteSetting(string _settingcode)
        {
            string returnval = String.Empty;

            using (MySqlConnection conn = new MySqlConnection(PortalUtility.GetConnectionString("default")))
            {
                conn.Open();
                returnval = GetSiteSetting(_settingcode, conn);
                conn.Close();
            }
            return(returnval);
        }
        public static string SendEmail(string _subject, string _body, string _mailto, string _mailfrom, string _fromdisplayname)
        {
            string error    = String.Empty;
            string smtpuser = String.Empty;
            string smtppass = String.Empty;

            try
            {
                using (MySqlConnection conn = new MySqlConnection(PortalUtility.GetConnectionString("default")))
                {
                    conn.Open();

                    smtpuser = GetSiteSetting("ContactUsername", conn);
                    smtppass = GetSiteSetting("ContactPassword", conn);

                    if (String.IsNullOrEmpty(_mailfrom))
                    {
                        _mailfrom = GetSiteSetting("ContactFrom", conn);
                    }

                    if (String.IsNullOrEmpty(_mailto))
                    {
                        _mailto = GetSiteSetting("ContactTo", conn);
                    }

                    conn.Close();
                }
                MailMessage mailmsg = new MailMessage();
                mailmsg.To.Add(_mailto);

                mailmsg.Subject = _subject;
                mailmsg.Body    = _body;
                mailmsg.From    = new MailAddress(_mailfrom, _fromdisplayname);

                if (HttpContext.Current.Request.ServerVariables["SERVER_NAME"] == "localhost")
                {
                    return(String.Empty);
                    //mailmsg.To.Clear();
                    //mailmsg.To.Add("alternate email to");
                }

                SmtpClient client = new SmtpClient();
                client.Credentials = new System.Net.NetworkCredential(smtpuser, smtppass);
                client.Send(mailmsg);
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }
            return(error);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the user's role from the database
        /// </summary>
        /// <param name="userid">User id to look up</param>
        /// <returns>string of roles delimited by |</returns>
        /// <remarks>This method is only called if the roles are not found in a cookie</remarks>
        private string GetUserRoles(string userid)
        {
            string rolelist = string.Empty;

            //build a delimited string of the roles
            using (MySqlConnection conn = new MySqlConnection(PortalUtility.GetConnectionString("default")))
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand("Security_Select_UserRoles", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@pUsername", userid);
                using (MySqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        rolelist += dr["RoleName"].ToString() + "|";
                    }
                }
                conn.Close();
            }
            rolelist = rolelist.TrimEnd('|');

            return(rolelist);
        }