Exemplo n.º 1
0
        static public Membership.UserAuthenticateResults Login(string Email, string Password, bool GenerateRememberMeCookie)
        {
            Int64 SupplierId;

            Membership.UserAuthenticateResults results = Membership.AuthenticateSupplier(Email, Password, out SupplierId);
            if (results != Membership.UserAuthenticateResults.Success)
            {
                return(results);
            }

            AppSupplierAuthToken token = AuthTokens.GenerateAuthTokenForAppSupplierId(SupplierId, GenerateRememberMeCookie ? AuthTokenTimeSpan : 0);

            if (token == null)
            {
                return(Membership.UserAuthenticateResults.LoginError);
            }

            if (GenerateRememberMeCookie)
            {
                HttpCookie cookie = new HttpCookie(@"auth-token", TeaEncryptor.Encrypt(token.Secret.ToString(@"N") + @":" + token.Key, RememberMeCookieEncryptionKey));
                cookie.Expires = token.Expiry;
                HttpContext.Current.Response.Cookies.Add(cookie);
            }

            HttpContext.Current.Session[@"Authenticated"] = true;
            HttpContext.Current.Session[@"AuthTokenId"]   = token.AppSupplierAuthTokenId;
            HttpContext.Current.Session[@"SupplierId"]    = SupplierId;
            AppSupplier supplier = AppSupplier.FetchByID(SupplierId);

            HttpContext.Current.Session[@"IsProductSupplier"] = (supplier != null ? supplier.IsProduct : false);
            //HttpContext.Current.Session[@"LangCode"] = dg.Sql.Query.New<AppSupplier>().Select(AppSupplier.Columns.LangCode).Where(AppSupplier.Columns.SupplierId, SupplierId).ExecuteScalar() as string;

            return(results);
        }
Exemplo n.º 2
0
        static public Membership.UserAuthenticateResults Login(string Email, string Password, bool GenerateRememberMeCookie)
        {
            Int64 UserId;

            Membership.UserAuthenticateResults results = Membership.AuthenticateUser(Email, Password, out UserId);
            if (results != Membership.UserAuthenticateResults.Success)
            {
                return(results);
            }

            UserAuthToken token = AuthTokens.GenerateAuthTokenForUserId(UserId, GenerateRememberMeCookie ? AuthTokenTimeSpan : 0);

            if (token == null)
            {
                return(Membership.UserAuthenticateResults.LoginError);
            }

            if (GenerateRememberMeCookie)
            {
                HttpCookie cookie = new HttpCookie(@"auth-token", TeaEncryptor.Encrypt(token.Secret.ToString(@"N") + @":" + token.Key, RememberMeCookieEncryptionKey));
                cookie.Expires = token.Expiry;
                HttpContext.Current.Response.Cookies.Add(cookie);
            }

            HttpContext.Current.Session[@"Authenticated"] = true;
            HttpContext.Current.Session[@"AuthTokenId"]   = token.UserAuthTokenId;
            HttpContext.Current.Session[@"UserId"]        = UserId;
            HttpContext.Current.Session[@"LangCode"]      = dg.Sql.Query.New <UserProfile>().Select(UserProfile.Columns.DefaultLangCode).Where(UserProfile.Columns.UserId, UserId).ExecuteScalar() as string;

            return(results);
        }