Пример #1
0
        /// <summary>
        /// This method authenticates the login credentials passed
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="logon">The clear form logon name of the user</param>
        /// <param name="password">The clear form password of the user</param>
        /// <returns>An inner variable which is a <see cref="AuthResult"/></returns>
        public AuthResult Authenticate(string logon, string password)
        {
            var result = new AuthResult();

            CustomerDataSet users = GetCustomerByLogon(logon);

            if (users.Customer.Count == 0)
            {
                //user unknown
                result.ExtraMessage = string.Format("the user is unknown.");
            }
            else
            {
                //there is a user with such logon
                //now check the password
                if (Utils.IsEqual(users.Customer[0].Hash, password))
                {
                    /*//the password is correct
                    result.ReturnCode = LoginReturn.Success;
                    result.Success = true;
                    _userId = users.User[0].UserId;
                    result.UserId = _userId.ToString();
                    result.UserToken = Utils.GenerateUserToken();
                    _userToken = result.UserToken;
                    lastOperationDateTime = DateTime.Now;
                    result.UserFullName = string.Format("{0} {1}", users.User[0].FirstName, users.User[0].LastName);
*/
                    switch (users.Customer[0].StatusId)
                    {
                        case 1:
                            result.ReturnCode = LoginReturn.Success;
                            result.Success = true;
                            _userId = users.Customer[0].CustomerId;
                            result.UserId = users.Customer[0].CustomerId.ToString();
                            result.UserToken = Utils.GenerateUserToken();
                            _userToken = result.UserToken;
                            lastOperationDateTime = DateTime.Now;
                            result.UserFullName = string.Format("{0} {1}", users.Customer[0].FirstName,
                                                                users.Customer[0].LastName);

                            break;
                        case 2:
                            result.ReturnCode = LoginReturn.InactiveUser;
                            result.Success = false;
                            _userId = users.Customer[0].CustomerId;
                            result.UserId = users.Customer[0].CustomerId.ToString();
                            result.UserToken = Utils.GenerateUserToken();
                            _userToken = result.UserToken;
                            lastOperationDateTime = DateTime.Now;
                            result.UserFullName = string.Format("{0} {1}", users.Customer[0].FirstName,
                                                                users.Customer[0].LastName);
                            break;

                        case 3:
                            result.Success = false;
                            result.ReturnCode = LoginReturn.DeletedUser;
                            break;

                        case 4:
                            result.Success = false;
                            result.ReturnCode = LoginReturn.ExpiredCredentials;
                            break;
                    }

                }
                else
                {
                    //the password is wrong
                    result.ExtraMessage = string.Format("the password is incorrect.");
                }

            }

            return result;
        }
Пример #2
0
        /// <summary>
        /// This method authenticates the login credentials passed
        /// </summary>
        /// <param name="orgId"></param>
        /// <param name="logon">The clear form logon name of the user</param>
        /// <param name="password">The clear form password of the user</param>
        /// <returns>An inner variable which is a <see cref="AuthResult"/></returns>
        public AuthResult Authenticate(string logon, string password)
        {
            var result = new AuthResult();

            CustomerDataSet users = GetCustomerByLogon(logon);

            if (users.Customer.Count == 0)
            {
                //user unknown
                result.ExtraMessage = string.Format("the user is unknown.");
            }
            else
            {
                //there is a user with such logon
                //now check the password
                if (Utils.IsEqual(users.Customer[0].Hash, password))
                {
                    /*//the password is correct
                     * result.ReturnCode = LoginReturn.Success;
                     * result.Success = true;
                     * _userId = users.User[0].UserId;
                     * result.UserId = _userId.ToString();
                     * result.UserToken = Utils.GenerateUserToken();
                     * _userToken = result.UserToken;
                     * lastOperationDateTime = DateTime.Now;
                     * result.UserFullName = string.Format("{0} {1}", users.User[0].FirstName, users.User[0].LastName);
                     */
                    switch (users.Customer[0].StatusId)
                    {
                    case 1:
                        result.ReturnCode     = LoginReturn.Success;
                        result.Success        = true;
                        _userId               = users.Customer[0].CustomerId;
                        result.UserId         = users.Customer[0].CustomerId.ToString();
                        result.UserToken      = Utils.GenerateUserToken();
                        _userToken            = result.UserToken;
                        lastOperationDateTime = DateTime.Now;
                        result.UserFullName   = string.Format("{0} {1}", users.Customer[0].FirstName,
                                                              users.Customer[0].LastName);

                        break;

                    case 2:
                        result.ReturnCode     = LoginReturn.InactiveUser;
                        result.Success        = false;
                        _userId               = users.Customer[0].CustomerId;
                        result.UserId         = users.Customer[0].CustomerId.ToString();
                        result.UserToken      = Utils.GenerateUserToken();
                        _userToken            = result.UserToken;
                        lastOperationDateTime = DateTime.Now;
                        result.UserFullName   = string.Format("{0} {1}", users.Customer[0].FirstName,
                                                              users.Customer[0].LastName);
                        break;

                    case 3:
                        result.Success    = false;
                        result.ReturnCode = LoginReturn.DeletedUser;
                        break;

                    case 4:
                        result.Success    = false;
                        result.ReturnCode = LoginReturn.ExpiredCredentials;
                        break;
                    }
                }
                else
                {
                    //the password is wrong
                    result.ExtraMessage = string.Format("the password is incorrect.");
                }
            }

            return(result);
        }