Beispiel #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);
        }