public override bool ValidateUserRefreshToken(string token, IApplication application, out IUser user)
        {
            user  = null;
            token = _encryptionService.CreatePasswordHash(token);
            var dbMembership = _membershipRepository.Single(new Specification <Membership>(u => u.RefreshTokens.Any((t) => t.RefreshToken == token) && u.IsActive == true));

            using (_unitOfWorkFactory.Create())
            {
                if (dbMembership == null)
                {
                    return(false);
                }

                dbMembership.LastLoginDate = DateTime.UtcNow;
            }
            var appid = Convert.ToInt32(application.Id);

            user = new MembershipDto()
            {
                Id             = dbMembership.Id.ToString(),
                Username       = dbMembership.UserName,
                Roles          = new[] { "user" },
                TokenIssueDate = dbMembership.RefreshTokens.First(a => a.ApplicationId == appid).IssuedUtc
            };
            ((MembershipDto)user).SetAddionalResponceParams(dbMembership);
            return(true);
        }
        protected override bool Validate(RegisterUserModel param, IApplication application, out IUser user)
        {
            user = null;
            Customer customer;

            if (param.FullName == null || param.FullName == string.Empty)
            {
                return(false);
            }

            if (param.Password == null || param.Password == string.Empty)
            {
                return(false);
            }

            if (param.Email == null || param.Email == string.Empty)
            {
                return(false);
            }

            if (param.Mobile == null || param.Mobile == string.Empty)
            {
                return(false);
            }

            var dbMembership = _membershipRepository.First(new Specification <Membership>(u => u.UserName.ToLower() == param.Email.ToLower()));

            if (dbMembership != null)
            {
                return(false);
            }

            using (var uow = _unitOfWorkFactory.Create())
            {
                var enSaltKey  = _encryptionService.CreateSaltKey(8);
                var enPassword = _encryptionService.CreatePasswordHash(param.Password, enSaltKey);

                dbMembership = new Membership()
                {
                    PasswordSalt = enSaltKey,
                    Password     = enPassword,
                    CreatedOn    = DateTime.UtcNow,
                    IsActive     = true,
                    UserName     = param.Email,
                    Role         = _roleRepository.First(new Specification <Role>(r => r.Name == "User"))
                };

                customer = new Customer()
                {
                    Membership = dbMembership,
                    Name       = param.FullName,
                    Mobile     = param.Mobile,
                    Email      = param.Email
                };
                _customerRepository.Add(customer);
            }
            user = new MembershipDto()
            {
                Id       = dbMembership.Id.ToString(),
                Username = dbMembership.UserName,
                Roles    = new[] { dbMembership.Role.Name }
            };
            ((MembershipDto)user).SetAddionalResponceParams(dbMembership);
            return(true);
        }
예제 #3
0
        protected override bool Validate(CopyLiPasswordGrantType param, IApplication application, out IUser member)
        {
            // Check for better solution
            string token = HttpContext.Current.Request.Form["pushNotificationToken"];

            member = null;
            var dbMembership = _membershipsRepository.First(new Specification <Membership>(u => u.UserName.ToLower() == param.Username.ToLower()));

            if (dbMembership == null)
            {
                return(false);
            }

            var passwordHash = _encryptionService.CreatePasswordHash(param.Password, dbMembership.PasswordSalt);

            if (passwordHash != dbMembership.Password)
            {
                return(false);
            }

            if (dbMembership.IsActive != true)
            {
                return(false);
            }
            member = new MembershipDto()
            {
                Id       = dbMembership.Id.ToString(),
                Username = dbMembership.UserName,
                //Roles = new[] { dbMembership.Role.Name },
                Roles = new[] { "Admin" },
            };

            ((MembershipDto)member).SetAddionalResponceParams(dbMembership);

            var dbCustomer = _customersRepository.First(new Data.Specifications.Customers.ByMembershipId(dbMembership.Id));
            var dbVendor   = _vendorRepository.First(new Data.Specifications.Vendors.ByMembershipId(dbMembership.Id));
            var dbAdmin    = _adminRepository.First(new ByMemberShipId(dbMembership.Id));

            // Add Validation for application
            if (dbCustomer == null)
            {
                if (dbVendor == null)
                {
                    if (dbAdmin == null)
                    {
                        return(false);
                    }
                    ((MembershipDto)member).SetAddionalResponceParams(dbAdmin);
                }
                else
                {
                    ((MembershipDto)member).SetAddionalResponceParams(dbVendor);
                    using (var uow = _unitOfWorkFactory.Create())
                    {
                        dbVendor.Token = token;
                    }
                }
            }
            else
            {
                ((MembershipDto)member).SetAddionalResponceParams(dbCustomer);
                using (var uow = _unitOfWorkFactory.Create())
                {
                    dbCustomer.Token = token;
                }
            }
            return(true);
        }