Ejemplo n.º 1
0
        /// <summary>
        /// Activate member
        /// </summary>
        /// <param name="param">Activate Request Model</param>
        /// <remarks></remarks>
        public ActivateResultModel Activate(ActivateRequestModel param)
        {
            ActivateResultModel result = new ActivateResultModel();

            try
            {
                MemberBL bl = new MemberBL();

                var member = bl.Activate(param);
                var token  = IdentityHelper.GenerateToken(member);

                bl.RegisterToken(token);

                result.AccessToken = token.Token;
                result.Status      = true;
                result.Message     = "Activated!";
            }
            catch (OrgException oex)
            {
                result.Status  = false;
                result.Message = oex.Message;
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = AppConfigs.InternalErrorMessage;

                if (AppConfigs.DebugInternalMessage)
                {
                    result.InternalMessage = ex.Message;
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sign-in and get member information
        /// </summary>
        /// <param name="param">SignIn Request Model</param>
        /// <remarks></remarks>
        public ProfileResultModel SignIn(SignInRequestModel param)
        {
            ProfileResultModel result = new ProfileResultModel();

            if (!this.ModelState.IsValid)
            {
                result.Status  = false;
                result.Message = this.ModelState.Values.Single(v => v.Errors.Count > 0).Errors.FirstOrDefault().ErrorMessage;

                return(result);
            }

            try
            {
                MemberBL bl = new MemberBL();

                var member = bl.SignIn(param);

                if (member == null)
                {
                    result.Status  = false;
                    result.Message = "Invalid user name";
                }
                else
                {
                    var token = IdentityHelper.GenerateToken(member);

                    bl.RegisterToken(token);

                    result.Status             = true;
                    result.Message            = "Sign-in successfully";
                    result.Member             = member;
                    result.Member.AccessToken = token.Token;
                }
            }
            catch (OrgException oex)
            {
                result.Status  = false;
                result.Message = oex.Message;
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = AppConfigs.InternalErrorMessage;

                if (AppConfigs.DebugInternalMessage)
                {
                    result.InternalMessage = ex.Message;
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public void TestActivatedAccountSuccess()
        {
            var claims = new Claim[]
            {
                new Claim(ClaimTypes.Name, testAccount.Id.ToString()),
                new Claim(ClaimTypes.Authentication, "false"),
            };
            var tokenConfig = appSettings.Value.TokenConfig;
            var token       = IdentityHelper.GenerateToken(tokenConfig.Secret, tokenConfig.Issuer, tokenConfig.Audience, claims, tokenConfig.Expires);
            var result      = service.ActivateAccount(token);

            Assert.AreEqual(true, result.IsSuccess);
            Assert.AreEqual(IdentityResultCode.Success, result.ResultCode);
        }
Ejemplo n.º 4
0
        public void TestResetPasswordSuccess()
        {
            var claims = new Claim[]
            {
                new Claim(ClaimTypes.Email, testAccount.Email)
            };
            var tokenConfig = appSettings.Value.TokenConfig;
            var token       = IdentityHelper.GenerateToken(tokenConfig.Secret, tokenConfig.Issuer, tokenConfig.Audience, claims, tokenConfig.Expires);
            var request     = new ResetPasswordRequest
            {
                Token       = token,
                NewPassword = "******"
            };
            var result = service.ResetPassword(request);

            Assert.AreEqual(true, result.IsSuccess);
            Assert.AreEqual(IdentityResultCode.Success, result.ResultCode);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Revoke authentication token
        /// </summary>
        /// <param name="param">Revoke Auth Request Model</param>
        /// <remarks></remarks>
        public RevokeAuthResultModel RevokeAuth(RevokeAuthRequestModel param)
        {
            RevokeAuthResultModel result = new RevokeAuthResultModel();

            try
            {
                MemberBL bl = new MemberBL();

                var member = bl.GetTokenOwner(new TokenModel {
                    Token = param.AccessToken
                });
                var token = IdentityHelper.GenerateToken(member);

                bl.RegisterToken(token);

                result.AccessToken = token.Token;
                result.Status      = true;
                result.Message     = "Revoke authentication successfully.";
            }
            catch (OrgException oex)
            {
                result.Status  = false;
                result.Message = oex.Message;
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = AppConfigs.InternalErrorMessage;

                if (AppConfigs.DebugInternalMessage)
                {
                    result.InternalMessage = ex.Message;
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
 private string MakeToken(Claim[] claims)
 {
     return(IdentityHelper.GenerateToken(_appSettings.TokenConfig.Secret, _appSettings.TokenConfig.Issuer,
                                         _appSettings.TokenConfig.Audience, claims, _appSettings.TokenConfig.Expires));
 }