示例#1
0
        public IList <UserProfile> Profiles(string ids)
        {
            if (string.IsNullOrEmpty(ids))
            {
                return(null);
            }

            var idsArray = ids.Split(',');
            var idList   = new List <long>(idsArray.Length);

            foreach (var item in idsArray)
            {
                var id = 0L;
                if (long.TryParse(item, out id))
                {
                    idList.Add(id);
                }
            }

            var passports = UserPassport.FindByIds(idList);

            IList <UserProfile> profiles = null;

            if (null != passports && passports.Count > 0)
            {
                profiles = new List <UserProfile>(passports.Count);
                for (var i = 0; i < passports.Count; i++)
                {
                    profiles.Add(passports[i].Profile.FormatEntity());
                }
            }

            return(profiles);
        }
示例#2
0
        public ActionResult SignIn(string phone, string password)
        {
            if (string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(password))
            {
                return(Json(new { Success = false, Message = "手机号和密码不能为空" }));
            }

            var entity = new AccountSign()
            {
                MobilePhone = phone,
                Password    = password
            };

            UserPassport userPassport = null;
            var          success      = AccountAuthentication.SignIn(phone, password, null, out userPassport);

            if (!success)
            {
                return(Json(new { Success = false, Message = "手机号或密码错误" }));
            }

            var account = AnonymousAccount.FindLastByPassport(userPassport.PassportId);

            if (account == null)
            {
                return(Json(new { Success = false, Message = "Token已失效" }));
            }

            CookieHelper.SetCookie(AccountAuthentication.TokenKey, account.Token.AccessToken);
            return(Json(new { Success = true, Message = "登陆成功" }));
        }
        public AccountSignResult BindThirdPassport(ThirdPassport entity)
        {
            if (null == entity || string.IsNullOrEmpty(entity.Platform) || string.IsNullOrEmpty(entity.PlatformPassportId))
            {
                return(null);
            }
            var account = MvcContext.Current.ClientAccount;

            if (null == account)
            {
                return(null);
            }

            var          signStatus   = SignStatus.Error;
            UserPassport userPassport = AccountAuthentication.BindThirdPassport(entity, out signStatus);

            var result = new AccountSignResult();

            result.SignStatus = signStatus;
            if (result.SignStatus == SignStatus.Success)
            {
                result.Account = new AccountEntity(account, userPassport);
                WriteTokenToBrowser(result);
            }
            else
            {
                result.ErrorMessage = "绑定账号失败";
            }
            return(result);
        }
示例#4
0
        public void UserProfileTest()
        {
            var password = string.Format("P{0}", TestHelper.GetRndNumber(10000, 90000));
            var passport = SignUp(password);
            var profile  = passport.Profile;

            Assert.IsNotNull(profile);
            Assert.IsTrue(profile is UserProfile);

            Assert.IsNull(profile.RealName);

            TestHelper.FillRndProperties(profile, "Passport,PassportId,PersistentState,CreatedTime".Split(','));
            Assert.IsNotNull(profile.RealName);

            Assert.IsTrue(profile.Save());

            var newPassport = UserPassport.FindById(passport.PassportId);

            Assert.IsNotNull(newPassport);

            var newPofile = newPassport.Profile;

            Assert.IsNotNull(newPofile);
            Assert.IsTrue(newPofile is UserProfile);
            Assert.AreEqual(profile.RealName, newPofile.RealName);


            TestHelper.FillRndProperties(passport.Profile, "Passport,PassportId,PersistentState,CreatedTime".Split(','));
            Assert.IsTrue(profile.Save());
            Assert.AreNotEqual(profile.RealName, newPofile.RealName);
        }
示例#5
0
        public void MD5SecurityStrategyTest()
        {
            var oldHash  = "A1AFD14FE75EF537F43F5C27A4ECAFB";
            var email    = "*****@*****.**";
            var userName = "******";
            var password = "******";

            var userPassport = new UserPassport()
            {
                UserSecurity = new UserSecurity()
            };

            userPassport.Email    = email;
            userPassport.UserName = userName;
            userPassport.UserSecurity.HashAlgorithm = "MD5";
            userPassport.UserSecurity.PasswordSalt  = "829534";

            var securityStrategy = PassportSecurityProvider.LoadSecurityStrategy(userPassport.UserSecurity.HashAlgorithm);

            var hash = securityStrategy.HashPassword(password, userPassport);

            userPassport.UserSecurity.Password = hash;
            Assert.IsTrue(userPassport.UserSecurity.Password.Length > password.Length);
            Console.WriteLine("{0} => {1}", password, hash);

            var verified = securityStrategy.Verify(password, userPassport);

            Assert.IsTrue(verified);

            Assert.AreEqual(oldHash, hash);
        }
        public AccountSignResult ShortcutSignIn(AccountSign entity)
        {
            if (null == entity || string.IsNullOrEmpty(entity.MobilePhone) || string.IsNullOrEmpty(entity.ValidationCode))
            {
                return(null);
            }
            var account = MvcContext.Current.ClientAccount;

            if (null == account)
            {
                return(null);
            }

            var passportId = UserPassport.FindIdByMobilePhone(entity.MobilePhone);

            if (passportId == 0)
            {
                entity.Password = HashHelper.ComputeHash(entity.MobilePhone, HashAlgorithmName.SHA1).Substring(0, 6);
                return(SignUp(entity));
            }

            var isValid = MessageHelper.CheckSMSValidationCode(entity.MobilePhone, entity.ValidationCode);

            if (MvcContext.Current.Test && entity.ValidationCode == AppEnvironment.TestValidationCode)
            {
                isValid = true;
            }
            if (false == isValid)
            {
                return(new AccountSignResult()
                {
                    SignStatus = SignStatus.InvalidValidationCode,
                    ErrorMessage = "验证码无效,请重新获取"
                });
            }
            if (!string.IsNullOrEmpty(entity.InviteCode))
            {
                System.Web.HttpContext.Current.Items.Add(WorkplaceApplication.InviteCodeKey, entity.InviteCode);
            }
            UserPassport userPassport = null;
            var          isSignIn     = AccountAuthentication.SignIn(passportId, new SignedInLog(), out userPassport);

            var result = new AccountSignResult();

            result.SignStatus = isSignIn ? SignStatus.Success : SignStatus.InvalidPassword;
            if (result.SignStatus == SignStatus.Success)
            {
                result.Account          = new AccountEntity(account, userPassport);
                result.AdditionalAction = ProcessAdditionalAction(entity.AdditionalAction);

                WriteTokenToBrowser(result);
            }
            else
            {
                result.ErrorMessage = "用户名或密码错误";
            }
            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="password"></param>
        /// <param name="userPassport"></param>
        /// <returns></returns>
        internal static string HashPassword(string password, UserPassport userPassport)
        {
            ArgumentAssertion.IsNotNull(userPassport, "userPassport");
            ArgumentAssertion.IsNotNull(userPassport.UserSecurity, "userPassport.UserSecurity");

            var securityStrategy = LoadSecurityStrategy(userPassport.UserSecurity.HashAlgorithm);

            return(securityStrategy.HashPassword(password, userPassport));
        }
示例#8
0
        static string FormatPassword(int formatTimes, string password, UserPassport userPassport)
        {
            var result = password;

            for (var i = 0; i < formatTimes; i++)
            {
                result = FormatPassword(result, userPassport);
            }
            return(result);
        }
示例#9
0
        public ActionResult ConsultantApplyDetail(long id)
        {
            var model = UserPassport.FindById(id);

            if (null != model)
            {
                model.Profile.FormatEntity();
            }
            return(View(model));
        }
示例#10
0
        public bool ExistsMobilePhone(string phone)
        {
            if (string.IsNullOrEmpty(phone))
            {
                return(false);
            }
            var passportId = UserPassport.FindIdByMobilePhone(phone);

            return(passportId > 0);
        }
示例#11
0
        public UserProfile Profile(long id)
        {
            var userPassport = UserPassport.FindById(id);

            if (null == userPassport)
            {
                return(null);
            }

            return(userPassport.Profile.FormatEntity());
        }
示例#12
0
        public void FindByIdsTest()
        {
            var ids = new List <long>()
            {
                1, 2, 4
            };
            var list = UserPassport.FindByIds(ids);

            Assert.IsNotNull(list);
            Assert.AreEqual(list.Count, ids.Count);
        }
示例#13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="password"></param>
        /// <param name="userPassport"></param>
        /// <returns></returns>
        bool IPassportSecurityStrategy.Verify(string password, UserPassport userPassport)
        {
            password.AssertNotNull("password");
            userPassport.AssertNotNull("userPassport");
            userPassport.UserSecurity.AssertNotNull("userPassport.UserSecurity");

            var formatTimes = GetFormatTimes(password, userPassport.UserSecurity.HashAlgorithm);

            password = FormatPassword(formatTimes, password, userPassport);
            return(BCrypt.Verify(password, userPassport.UserSecurity.Password));
        }
        public static bool SignIn(long passportId, SignedInLog info, out UserPassport passport)
        {
            var signInResult = MemberShip.SignIn(passportId, info, out passport);

            if (signInResult)
            {
                Authenticate(passport);
            }

            return(signInResult);
        }
        public static bool SignIn(string userKey, string password, SignedInLog info, out UserPassport passport)
        {
            var signInResult = MemberShip.SignIn(userKey, password, info, out passport);

            if (signInResult)
            {
                Authenticate(passport);
            }

            return(signInResult);
        }
示例#16
0
        public AccountSignResult ResetPassword(AccountSign entity)
        {
            if (null == entity || string.IsNullOrEmpty(entity.MobilePhone) ||
                string.IsNullOrEmpty(entity.Password) || string.IsNullOrEmpty(entity.ValidationCode))
            {
                return(null);
            }
            var account = MvcContext.Current.ClientAccount;

            if (null == account)
            {
                return(null);
            }

            var isValid = MessageHelper.CheckSMSValidationCode(entity.MobilePhone, entity.ValidationCode);

            if (MvcContext.Current.Test && entity.ValidationCode == AppEnvironment.TestValidationCode)
            {
                isValid = true;
            }
            if (false == isValid)
            {
                return(new AccountSignResult()
                {
                    SignStatus = SignStatus.InvalidValidationCode,
                    ErrorMessage = "验证码无效,请重新获取"
                });
            }

            var passportId = UserPassport.FindIdByMobilePhone(entity.MobilePhone);

            if (passportId < 1)
            {
                return(new AccountSignResult()
                {
                    SignStatus = SignStatus.InvalidMobilePhone,
                    ErrorMessage = "手机号未注册"
                });
            }

            var isChanged = MemberShip.ChangePassword(passportId, entity.Password);

            if (isChanged)
            {
                return(new AccountSignResult()
                {
                    SignStatus = SignStatus.Success
                });
            }
            return(new AccountSignResult()
            {
                SignStatus = SignStatus.Failed
            });
        }
示例#17
0
        public void FindByIdTest()
        {
            var model = CreateNewModel();
            var id    = model.Id;

            var repository = RepositoryManager.GetRepository <IUserProfileRepository>(ModuleEnvironment.ModuleName);
            var entry      = UserPassport.FindById(id).UserSecurity;

            Assert.NotNull(entry);

            TestHelper.AssertObject(model, entry);
        }
示例#18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="account"></param>
        /// <param name="passport"></param>
        public AccountEntity(AnonymousAccount account, UserPassport passport)
        {
            this.SetPropertyValues(account.GetPropertyValues());
            if (null != passport && null != passport.Profile)
            {
                this.UserProfile = passport.Profile;

                this.MobilePhone      = passport.MobilePhone;
                this.MultipleProfiles = passport.MultipleProfiles;
                this.IMAccount        = AccountAuthentication.LoadIMAccount(passport.Profile);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="password"></param>
        /// <param name="userPassport"></param>
        /// <returns></returns>
        bool IPassportSecurityStrategy.Verify(string password, UserPassport userPassport)
        {
            password.AssertNotNull("password");
            userPassport.AssertNotNull("userPassport");
            userPassport.UserSecurity.AssertNotNull("userPassport.UserSecurity");

            password = FormatPassword(password, userPassport);
            var formatTimes  = GetFormatTimes(password, userPassport.UserSecurity.HashAlgorithm);
            var passwordHash = ComputeHash(password, formatTimes);

            return(passwordHash == userPassport.UserSecurity.Password);
        }
示例#20
0
        internal UserPassport CreateNewModel()
        {
            var ignores = ignoreProperties.Split(',');
            var model   = new UserPassport();

            TestHelper.FillRndProperties(model, ignores);

            var saveResult = model.Save();

            Assert.IsTrue(saveResult);
            return(model);
        }
示例#21
0
        public void DeleteTest()
        {
            var model = CreateNewModel();
            var id    = model.Id;

            model.Delete();

            var entry = UserPassport.FindById(id);

            Assert.IsNotNull(entry);
            Assert.AreEqual(PassportStatus.Cancellation, entry.PassportStatus);
        }
        public static GratuityJournalEntity ToEntity(this GratuityJournal item)
        {
            if (null == item)
            {
                return(null);
            }

            var profile = (OrganizationProfile)UserPassport.FindById(item.BuyerId).Profile;

            var entity = new GratuityJournalEntity(item, profile);

            return(entity);
        }
示例#23
0
        public void SignInTest()
        {
            var password    = string.Format("P{0}", TestHelper.GetRndNumber(10000, 90000));
            var passport    = SignUp(password);
            var mobilePhone = passport.MobilePhone;

            Assert.IsTrue(MemberShip.SignIn(mobilePhone, password));

            UserPassport newPassport  = null;
            var          signInResult = MemberShip.SignIn(mobilePhone, password, out newPassport);

            TestHelper.AssertObject(passport, newPassport);
        }
示例#24
0
        public ActionResult user(long oid)
        {
            var userPassport = UserPassport.FindById(oid);

            if (null == userPassport)
            {
                return(View("error"));
            }

            var entity = new UserPageEntity();

            entity.Profile = userPassport.Profile;
            return(View(entity));
        }
        public ConsultantPageEntity Page(long id)
        {
            var userPassport = UserPassport.FindById(id);

            if (null == userPassport)
            {
                return(null);
            }

            var entity = new ConsultantPageEntity();

            entity.Profile = (OrganizationProfile)userPassport.Profile.FormatEntity();
            return(entity);
        }
        private void MemberShip_OnSignUp(UserPassport passport)
        {
            var phoneDic = BizDictionary.GetSimpleDictionary(BizDictionary.Listeners_SignUp);

            if (null != phoneDic && phoneDic.Count > 0)
            {
                var phones  = string.Join(",", phoneDic.Keys.ToArray());
                var content = string.Format("{0}用户 {1} 刚刚注册,请及时联系用户"
                                            , passport.ProfileType == ProfileType.OrganizationProfile ? "企业" : "个人", passport.MobilePhone);
                MessageHelper.SendSMS("SendNotify", 0, phones, content);
            }

            this.AddInvitedRelationship(passport);
        }
示例#27
0
        UserPassport SignUp(string password)
        {
            var phone = string.Format("17{0}", TestHelper.GetRndNumber(100000000, 900000000));

            var signedUpInfo = new SignedUpInfo();

            signedUpInfo.SignedUpIp = "127.0.0.1";
            var          status   = SignUpStatus.Error;
            UserPassport passport = MemberShip.SignUp(phone, password, signedUpInfo, out status);

            Assert.AreEqual(SignUpStatus.Success, status);

            Console.WriteLine("SignUp({0},{1}) => {2}", phone, password, passport.PassportId);
            return(passport);
        }
示例#28
0
        static string FormatPassword(string password, UserPassport userPassport)
        {
            var factorParams = new[]
            {
                password,
                ModuleEnvironment.HashSalt,
                userPassport.CreatedTime.ToString("ssmmHHddMMyy").ToString(),
                userPassport.UserSecurity.PasswordSalt,
                userPassport.UserSecurity.HashAlgorithm
            }.OrderBy(x => x).ToArray();

            var passwordFactors = string.Join("", factorParams);

            return(HashHelper.ComputeHash(passwordFactors, HashAlgorithmName.SHA256));
        }
        public static void Authenticate(UserPassport passport)
        {
            if (null == passport)
            {
                SignOut();
            }
            else
            {
                MvcContext.Current.PassportId = passport.PassportId;
                if (null != MvcContext.Current.ClientAccount)
                {
                    MvcContext.Current.ClientAccount.PassportId = passport.PassportId;
                    MvcContext.Current.ClientAccount.Save();
                }

                //SyncIMAccount(passport);
            }
        }
        public static void SyncIMAccount(UserPassport passport)
        {
            return; // not using im

            var currentProfileType = ProfileType.UserProfile;

            if (passport.Profile is OrganizationProfile)
            {
                currentProfileType = ((OrganizationProfile)passport.Profile).CurrentProfileType;
            }

            var imAccount = new ThirdIMAccount();

            imAccount.Platform          = ModuleEnvironment.IMProviderName;
            imAccount.PlatformAccountId = string.Concat(ProfileType.OrganizationProfile == currentProfileType ? "cc-" : "u-", passport.PassportId);
            imAccount.Nickname          = ProfileType.OrganizationProfile == currentProfileType ? passport.Profile.RealName : passport.Profile.Nickname;

            TrySyncIMAccount(imAccount);
        }