another business/logic suggestion!

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
8/4/2011 7:12:17 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

another business/logic suggestion!

Dear Joe,

Here a situation faced my client; he said that lets suppose someone knows your login email (which is such familiar thing); and he just wanted to lock you, so, he typed wrong password for the site limit times, and you are locked now; is it logic that both the user and the administrator must at least receive email about that? or at least the user himself (please contact the website administrator...etc).

The point:

it is good if the user received email that his account locked in both sides if someone or if he did that, and not bad "optionally" to send the administrator if he want (in web.config) to receive such emails.

Just a suggestion, no need to reply for it, with thanks and sorry for disturbing.

 

 

 

8/4/2011 7:13:55 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: another business/logic suggestion!

sorry, because if i came to sign in and found that my account locked i will be confused, cause i did not recive any notifications about that.

8/4/2011 7:27:08 AM
Gravatar
Total Posts 18439

Re: another business/logic suggestion!

I'm pretty sure the lockout is only temporary not permanent, so within 15 minutes I "think" the user could login again. And if the problem persists he can contact the site admin. It is also possible in the latest code to log failed login attempts in the log so a site admin could keep an eye out for them and could block the ip address if it found someone doing it on purpose.

<add key="LogFailedLoginAttempts" value="true" />

Hope that helps,

Joe

8/4/2011 7:33:54 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: another business/logic suggestion!

yes, it helped, it was just a business logic, and i will send them your answer :)

Ok, here another small issue, can be the link on avatar to open in a blank window instead of self, i mean when you click at your avatar image at your profile, it open in the same window!

I think it is better to make the target blank.

 

regards

8/4/2011 7:48:43 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: another business/logic suggestion!

I found it in web/controls/gravatar/gravatar.cs

is there any hope? :)

thanks

8/4/2011 7:54:53 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: another business/logic suggestion!

here the ready code:

using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.ComponentModel;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//namespace FreshClickMedia.Web.UI.WebControls
namespace mojoPortal.Web.UI
{
    /// <summary>
    ///
    ///
    /// Source: http://www.freshclickmedia.com/blog/2008/02/gravatar-aspnet-control/
    /// 2008-08-13 Joe Audette added to this project and changed namespace to be more convenient
    /// 2008-08-13 Joe Audette added support for SSL by returning the secure url if request is secure
    ///
    /// </summary>
    [
    DefaultProperty("Email"),
    ToolboxData("<{0}:Gravatar runat=server></{0}:Gravatar>")
    ]
    public class Gravatar : System.Web.UI.WebControls.WebControl
    {
        public const string SecureUrl = "https://secure.gravatar.com/avatar/";
        public const string StandardUrl = "http://www.gravatar.com/avatar/";

        public enum RatingType { G, PG, R, X }

        private string _email;
        private short _size = 80;
        private RatingType _maxAllowedRating;
        private string _defaultImage;

        // outut gravatar site link true by default:
        private bool _outputGravatarSiteLink = true;

        // customise the link title:
        private string _linkTitle = "Get your avatar";
        private string _linkUrl = "http://www.gravatar.com";
        private string _LinkTarget = "_blank";

        /// <summary>
        /// The Email for the user
        /// </summary>
        [Bindable(true), Category("Appearance"), DefaultValue("")]
        public string Email
        {
            get { return _email; }
            set { _email = value.ToLower(); }
        }

        /// <summary>
        /// Size of Gravatar image.  Must be between 1 and 512.
        /// </summary>
        [Bindable(true), Category("Appearance"), DefaultValue("80")]
        public short Size
        {
            get { return _size; }
            set { _size = value; }
        }

        /// <summary>
        /// An optional "rating" parameter may follow with a value of [ G | PG | R | X ] that determines the highest rating (inclusive) that will be returned.
        /// </summary>
        public RatingType MaxAllowedRating
        {
            get { return _maxAllowedRating; }
            set { _maxAllowedRating = value; }
        }
       
        /// <summary>
        /// Determines whether the image is wrapped in an anchor tag linking to the Gravatar sit
        /// </summary>
        public bool OutputGravatarSiteLink
        {
            get { return _outputGravatarSiteLink; }
            set { _outputGravatarSiteLink = value; }
        }

        /// <summary>
        /// Optional property for link title for gravatar website link
        /// </summary>
        public string LinkTitle
        {
            get { return _linkTitle; }
            set {_linkTitle = value; }
        }

        public string LinkTarget
        {
            get { return _LinkTarget; }
            set { _LinkTarget = value; }
       }
        /// <summary>
        /// By default links to Gravatar so users can get a gravatar, but you can override it and link to a user profile for example
        /// </summary>
        public string LinkUrl
        {
            get { return _linkUrl; }
            set { _linkUrl = value; }
        }
       
        /// <summary>
        /// An optional "default" parameter may follow that specifies the full, URL encoded URL, protocol included, of a GIF, JPEG, or PNG image that should be returned if either the requested email address has no associated gravatar, or that gravatar has a rating higher than is allowed by the "rating" parameter.
        /// </summary>
        [Bindable(true), Category("Appearance"), DefaultValue("")]
        public string DefaultImage
        {
            get { return _defaultImage; }
            set { _defaultImage = value; }
        }

        /// <summary>
        /// Gets the base Url based on whether the request is secure or not.
        /// Added by Joe Audette 2008-08-13
        /// </summary>
        public string GravatarBaseUrl
        {
            get
            {
                if (Page.Request.IsSecureConnection) { return SecureUrl; }
                return StandardUrl;
            }
        }

       
        protected override void Render(HtmlTextWriter output)
        {
            if (HttpContext.Current == null)
            {
                output.Write("[" + this.ID + "]");
                return;
            }

            // output the default attributes:
            AddAttributesToRender(output);

            // if the size property has been specified, ensure it is a short, and in the range
            // 1..512:
            try
            {
                // if it's not in the allowed range, throw an exception:
                if (Size < 1 || Size > 512)
                    throw new ArgumentOutOfRangeException();
            }
            catch
            {
                Size = 80;
            }

            // default the image url:
            //string imageUrl = "http://www.gravatar.com/avatar.php?";
            // changes by Joe Audette 2008-08-13
            string imageUrl = GravatarBaseUrl;
           
            if( !string.IsNullOrEmpty( Email))
            {
                // build up image url, including MD5 hash for supplied email:
                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

                UTF8Encoding encoder = new UTF8Encoding();
                MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();

                byte[] hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(Email));

                StringBuilder sb = new StringBuilder(hashedBytes.Length * 2);
                for (int i = 0; i < hashedBytes.Length; i++)
                {
                    sb.Append(hashedBytes[i].ToString("X2"));
                }

                // output parameters:
                //imageUrl += "gravatar_id=" + sb.ToString().ToLower();
                //imageUrl += "&rating=" + MaxAllowedRating.ToString();
                //imageUrl += "&size=" + Size.ToString();

                // changes by Joe Audette 2008-08-13
                imageUrl += sb.ToString().ToLower();
                imageUrl += ".jpg?r=" + MaxAllowedRating.ToString();
                imageUrl += "&s=" + Size.ToString();
            }

            // output default parameter if specified
            if (!string.IsNullOrEmpty(DefaultImage))
            {
                imageUrl += "&default=" + HttpUtility.UrlEncode(DefaultImage);
            }

            // if we need to output the site link:
            if (OutputGravatarSiteLink)
            {
                output.AddAttribute(HtmlTextWriterAttribute.Href, LinkUrl);
                output.AddAttribute(HtmlTextWriterAttribute.Title, LinkTitle);
                output.AddAttribute(HtmlTextWriterAttribute.Target, LinkTarget);

                output.RenderBeginTag(HtmlTextWriterTag.A);
            }
           
            // output required attributes/img tag:
            output.AddAttribute(HtmlTextWriterAttribute.Width, Size.ToString());
            output.AddAttribute(HtmlTextWriterAttribute.Height, Size.ToString());
            output.AddAttribute(HtmlTextWriterAttribute.Src, imageUrl);
            output.AddAttribute(HtmlTextWriterAttribute.Alt, "Gravatar");
            output.RenderBeginTag("img");
            output.RenderEndTag();

            // if we need to output the site link:
            if (OutputGravatarSiteLink)
            {
                output.RenderEndTag();
            }
        }
    }
}

8/4/2011 7:56:09 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: another business/logic suggestion!

I just added :

private string _LinkTarget = "_blank";

and its values

 

regards

 

8/4/2011 8:12:10 AM
Gravatar
Total Posts 18439

Re: another business/logic suggestion!

Hi Ghalib,

Please help me keep the forums organized by asking only one question/topic per thread.

I don't think links should open in new windows, target is not a valid attribute in xhtml nor in html 5. See the article Links Should Not Open in a New Window for information why and also for a way to do it if you really want to open in new windows anyway.

I will make it possible to use a CSS class on the Gravatar link like this:

if (CssClass.Length > 0)
{
        output.AddAttribute(HtmlTextWriterAttribute.Class, CssClass);
   }

then you could set a class in theme.skin like this:

<portal:Gravatar runat="server CssClass="external" />

then you could use jquery to make all links with that class open in a new window, or javascript similar to the article linked above.

Hope that helps,

Joe

8/4/2011 8:51:27 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: another business/logic suggestion!

Ok, thank you, I will not do it again.

Best :)

8/4/2011 8:58:46 AM
Gravatar
Total Posts 18439

Re: another business/logic suggestion!

Hi Ghalib,

Many thanks for the beers! Much appreciated.

I'll tell you what, I'll make it easier if you really want to open the gravatar links in a new window and don't mind the invalid markup. I'll make it like this:

if (target.Length > 0)
  {
       output.AddAttribute(HtmlTextWriterAttribute.Target, target);
   }

that way by default it will render valid markup, but then you could do this in theme.skin:

<portal:Gravatar runat="server" Target="_blank" />

This will be in the repository later today.

Best,

Joe

8/4/2011 9:23:18 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: another business/logic suggestion!

I just try my best not to override mojo code, i made such huge work , which i will share it later as i finish my project at this Sunday, without changing mojo code and it was really beautiful solution with many tricks around.

http://www.aljidara.net/default.aspx

you still the best, thanks :)

You must sign in to post in the forums. This thread is closed to new posts.