コード例 #1
0
ファイル: DataProvider.cs プロジェクト: BraZee/IgniteMe
        /// <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();

            Customers users = GetCustomerByLogon(logon);

            if (users == null)
            {
                //user unknown
                result.ExtraMessage = string.Format("Unknown User!");
            }
            else
            {
                //there is a user with such logon
                //now check the password
                if (Utils.IsEqual(users.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.StatusId)
                    {
                    case 1:
                        result.ReturnCode     = LoginReturn.Success;
                        result.Success        = true;
                        _userId               = users.Id;
                        result.UserId         = users.Id.ToString();
                        result.UserToken      = Utils.GenerateUserToken();
                        _userToken            = result.UserToken;
                        lastOperationDateTime = DateTime.Now;
                        result.UserFullName   = string.Format("{0},{1},{2}", users.FirstName, users.MiddleName,
                                                              users.LastName);
                        result.ExtraMessage = users.Username;

                        break;

                    case 2:
                        result.ReturnCode     = LoginReturn.InactiveUser;
                        result.Success        = false;
                        _userId               = users.Id;
                        result.UserId         = users.Id.ToString();
                        result.UserToken      = Utils.GenerateUserToken();
                        _userToken            = result.UserToken;
                        lastOperationDateTime = DateTime.Now;
                        result.UserFullName   = string.Format("{0},{1},{2}", users.FirstName, users.MiddleName,
                                                              users.LastName);
                        result.ExtraMessage = users.Username;
                        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("Incorrect Password!");
                }
            }

            return(result);
        }
コード例 #2
0
ファイル: DataProvider.cs プロジェクト: BraZee/IgniteMe
        /// <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();

            Customers users = GetCustomerByLogon(logon);

            if (users == null)
            {
                //user unknown
                result.ExtraMessage = string.Format("Unknown User!");
            }
            else
            {
                //there is a user with such logon
                //now check the password
                if (Utils.IsEqual(users.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.StatusId)
                    {
                        case 1:
                            result.ReturnCode = LoginReturn.Success;
                            result.Success = true;
                            _userId = users.Id;
                            result.UserId = users.Id.ToString();
                            result.UserToken = Utils.GenerateUserToken();
                            _userToken = result.UserToken;
                            lastOperationDateTime = DateTime.Now;
                            result.UserFullName = string.Format("{0},{1},{2}", users.FirstName,users.MiddleName,
                                                                users.LastName);
                            result.ExtraMessage = users.Username;

                            break;
                        case 2:
                            result.ReturnCode = LoginReturn.InactiveUser;
                            result.Success = false;
                            _userId = users.Id;
                            result.UserId = users.Id.ToString();
                            result.UserToken = Utils.GenerateUserToken();
                            _userToken = result.UserToken;
                            lastOperationDateTime = DateTime.Now;
                            result.UserFullName = string.Format("{0},{1},{2}", users.FirstName, users.MiddleName,
                                                                users.LastName);
                            result.ExtraMessage = users.Username;
                            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("Incorrect Password!");
                }

            }

            return result;
        }