コード例 #1
0
        public BooleanErrorModel Register(UserModel user)
        {
            var returnodel = new BooleanErrorModel();

            try
            {
                if (user != null)
                {
                    var entetiUser = _Mapper.Map <User>(user);
                    entetiUser.Password = _PasswordEngine.GetHash(string.Concat(entetiUser.Password, _identity.Value.Salt));
                    entetiUser.Accounts.Add(new Account()
                    {
                        Balance = 0
                    });
                    _UOF.Users.Add(entetiUser);
                    _UOF.Save();

                    returnodel.Error = false;
                    return(returnodel);
                }
                returnodel.Error        = true;
                returnodel.ErrorMessage = "Empty user data.";
                return(returnodel);
            }
            catch (Exception exception)
            {
                returnodel.Error        = true;
                returnodel.ErrorMessage = "Thomething goes wrong!";
                return(returnodel);
            }
        }
コード例 #2
0
        private ClaimsIdentity GetIdentity(string username, string password)
        {
            var person = _Unit.Users.Get(username);

            if (person != null)
            {
                if (person.Password == PasswordEngine_.GetHash(string.Concat(password, Identity_.Value.Salt)))
                {
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimsIdentity.DefaultNameClaimType, person.UserName),
                        new Claim(ClaimsIdentity.DefaultRoleClaimType, person.Password)
                    };
                    ClaimsIdentity claimsIdentity =
                        new ClaimsIdentity(claims, "Token", ClaimsIdentity.DefaultNameClaimType,
                                           ClaimsIdentity.DefaultRoleClaimType);
                    return(claimsIdentity);
                }
            }

            return(null);
        }
コード例 #3
0
        public bool Register(UserModel User)
        {
            try
            {
                if (User != null)
                {
                    var entetiUser = _mapper.Map <User>(User);
                    entetiUser.Password = _passwordEngine.GetHash(string.Concat(entetiUser.Password, _identity.Value.Salt));
                    entetiUser.Accounts.Add(new Account()
                    {
                        Balance = 0
                    });
                    _UOF.Users.Add(entetiUser);
                    _UOF.Save();

                    return(true);
                }
                return(false);
            }
            catch (Exception exception)
            {
                return(false);
            }
        }