Exemplo n.º 1
0
        //1.topAreaCode应该取DIContainer.Resolve<IAreaSettingsManager>().Get().RootAreaCode,不应该公开出来;
        //2.parentAreaCode参数没必要加;
        //3.callback、selectTop没加注释,不知道什么意思;
        /// <summary>
        /// 输出地区选择器
        /// </summary>
        public static MvcHtmlString AreaSelector(this HtmlHelper htmlHelper, string id, string topAreaCode = "", string parentAreaCode = "", string currentAreaCode = "", int depth = 4, string callback = null, bool selectTop = true)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("参数名称id不能为空", "id");
            }
            htmlHelper.ViewData["id"]              = id;
            htmlHelper.ViewData["topAreaCode"]     = topAreaCode;
            htmlHelper.ViewData["parentAreaCode"]  = parentAreaCode;
            htmlHelper.ViewData["currentAreaCode"] = currentAreaCode;
            htmlHelper.ViewData["depth"]           = depth;
            htmlHelper.ViewData["callback"]        = callback;
            htmlHelper.ViewData["selectTop"]       = selectTop;

            htmlHelper.ViewData["login"]                  = "******";
            htmlHelper.ViewData["registerAreaCode"]       = "AreaCode";
            htmlHelper.ViewData["registerAreaName"]       = "AreaName";
            htmlHelper.ViewData["registerParentAreaCode"] = "ParentAreaCode";
            htmlHelper.ViewData["registerParentAreaName"] = "ParentAreaName";

            // 获取当前用户的注册地
            AreaService        areaService        = DIContainer.Resolve <AreaService>();
            UserProfileService userProfileService = new UserProfileService();
            IUser currentUser = UserContext.CurrentUser; //获取当前登录用户

            if (currentUser == null)
            {
                return(htmlHelper.DisplayForModel("AreaSelector"));
            }
            UserProfile userProfile = userProfileService.Get(currentUser.UserId);

            if (userProfile == null || string.IsNullOrEmpty(userProfile.NowAreaCode))
            {
                return(htmlHelper.DisplayForModel("AreaSelector"));
            }

            Area area = areaService.Get(userProfile.NowAreaCode);

            htmlHelper.ViewData["login"]                  = "******";
            htmlHelper.ViewData["registerAreaCode"]       = userProfile.NowAreaCode;
            htmlHelper.ViewData["registerAreaName"]       = area.Name;
            htmlHelper.ViewData["registerParentAreaCode"] = area.ParentCode;
            string parentAreaName = areaService.Get(area.ParentCode).Name;

            htmlHelper.ViewData["registerParentAreaName"] = parentAreaName;


            return(htmlHelper.DisplayForModel("AreaSelector"));
        }
        //1.topAreaCode应该取DIContainer.Resolve<IAreaSettingsManager>().Get().RootAreaCode,不应该公开出来;
        //2.parentAreaCode参数没必要加;
        //3.callback、selectTop没加注释,不知道什么意思;
        /// <summary>
        /// 输出地区选择器
        /// </summary> 
        public static MvcHtmlString AreaSelector(this HtmlHelper htmlHelper, string id, string topAreaCode = "", string parentAreaCode = "", string currentAreaCode = "", int depth = 4, string callback = null, bool selectTop = true)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("参数名称id不能为空", "id");
            }
            htmlHelper.ViewData["id"] = id;
            htmlHelper.ViewData["topAreaCode"] = topAreaCode;
            htmlHelper.ViewData["parentAreaCode"] = parentAreaCode;
            htmlHelper.ViewData["currentAreaCode"] = currentAreaCode;
            htmlHelper.ViewData["depth"] = depth;
            htmlHelper.ViewData["callback"] = callback;
            htmlHelper.ViewData["selectTop"] = selectTop;

            htmlHelper.ViewData["login"] = "******";
            htmlHelper.ViewData["registerAreaCode"] = "AreaCode";
            htmlHelper.ViewData["registerAreaName"] = "AreaName";
            htmlHelper.ViewData["registerParentAreaCode"] = "ParentAreaCode";
            htmlHelper.ViewData["registerParentAreaName"] = "ParentAreaName";

            // 获取当前用户的注册地
            AreaService areaService = DIContainer.Resolve<AreaService>();
            UserProfileService userProfileService = new UserProfileService();
            IUser currentUser = UserContext.CurrentUser; //获取当前登录用户

            if (currentUser == null)
            {
                return htmlHelper.DisplayForModel("AreaSelector");
            }
            UserProfile userProfile = userProfileService.Get(currentUser.UserId);
            if (userProfile == null || string.IsNullOrEmpty(userProfile.NowAreaCode))
            {
                return htmlHelper.DisplayForModel("AreaSelector");
            }

            Area area = areaService.Get(userProfile.NowAreaCode);
            htmlHelper.ViewData["login"] = "******";
            htmlHelper.ViewData["registerAreaCode"] = userProfile.NowAreaCode;
            htmlHelper.ViewData["registerAreaName"] = area.Name;
            htmlHelper.ViewData["registerParentAreaCode"] = area.ParentCode;
            string parentAreaName = areaService.Get(area.ParentCode).Name;
            htmlHelper.ViewData["registerParentAreaName"] = parentAreaName;

            return htmlHelper.DisplayForModel("AreaSelector");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 转换为EducationExperience用于数据库存储
        /// </summary>
        public EducationExperience AsEducationExperience(long userId)
        {
            EducationExperience educationExperience;

            if (Id > 0)
            {
                UserProfileService userProfileService = new UserProfileService();
                educationExperience           = userProfileService.GetEducationExperience(Id, userId);
                educationExperience.Degree    = this.Degree;
                educationExperience.School    = this.School;
                educationExperience.StartYear = this.StartYear;

                if (!string.IsNullOrEmpty(Department))
                {
                    educationExperience.Department = this.Department;
                }
                else
                {
                    educationExperience.Department = string.Empty;
                }
            }
            else
            {
                educationExperience           = EducationExperience.New();
                educationExperience.Degree    = this.Degree;
                educationExperience.School    = this.School;
                educationExperience.StartYear = this.StartYear;

                if (!string.IsNullOrEmpty(Department))
                {
                    educationExperience.Department = this.Department;
                }
                else
                {
                    educationExperience.Department = string.Empty;
                }

                educationExperience.UserId = userId;
            }
            return(educationExperience);
        }
        /// <summary>
        /// 转换为WorkExperience用于数据库存储
        /// </summary>
        public WorkExperience AsWorkExperience(long userId)
        {
            WorkExperience workExperience;
            if (Id > 0)
            {
                UserProfileService userProfileService = new UserProfileService();
                workExperience = userProfileService.GetWorkExperience(Id, userId);

                if (!string.IsNullOrEmpty(CompanyAreaCode))
                    workExperience.CompanyAreaCode = this.CompanyAreaCode;
                else
                    workExperience.CompanyAreaCode = string.Empty;

                workExperience.CompanyName = this.CompanyName;
                workExperience.EndDate = new DateTime(this.EndDate, 1, 1);
                workExperience.StartDate = new DateTime(this.StartDate, 1, 1);

                if (workExperience.StartDate > workExperience.EndDate)
                {
                    DateTime tempDate = workExperience.EndDate;
                    workExperience.EndDate = workExperience.StartDate;
                    workExperience.StartDate = tempDate;
                }

                if (!string.IsNullOrEmpty(JobDescription))
                    workExperience.JobDescription = this.JobDescription;
                else
                    workExperience.JobDescription = string.Empty;

            }
            else
            {
                workExperience = WorkExperience.New();

                if (!string.IsNullOrEmpty(CompanyAreaCode))
                    workExperience.CompanyAreaCode = this.CompanyAreaCode;
                else
                    workExperience.CompanyAreaCode = string.Empty;

                workExperience.CompanyName = this.CompanyName;
                workExperience.EndDate = new DateTime(this.EndDate, 1, 1);
                workExperience.StartDate = new DateTime(this.StartDate, 1, 1);

                if (workExperience.StartDate > workExperience.EndDate)
                {
                    DateTime tempDate = workExperience.EndDate;
                    workExperience.EndDate = workExperience.StartDate;
                    workExperience.StartDate = tempDate;
                }

                if (!string.IsNullOrEmpty(JobDescription))
                    workExperience.JobDescription = this.JobDescription;
                else
                    workExperience.JobDescription = string.Empty;

                workExperience.UserId = userId;
            }
            return workExperience;
        }
Exemplo n.º 5
0
        /// <summary>
        /// 转换为WorkExperience用于数据库存储
        /// </summary>
        public WorkExperience AsWorkExperience(long userId)
        {
            WorkExperience workExperience;

            if (Id > 0)
            {
                UserProfileService userProfileService = new UserProfileService();
                workExperience = userProfileService.GetWorkExperience(Id, userId);

                if (!string.IsNullOrEmpty(CompanyAreaCode))
                {
                    workExperience.CompanyAreaCode = this.CompanyAreaCode;
                }
                else
                {
                    workExperience.CompanyAreaCode = string.Empty;
                }

                workExperience.CompanyName = this.CompanyName;
                workExperience.EndDate     = new DateTime(this.EndDate, 1, 1);
                workExperience.StartDate   = new DateTime(this.StartDate, 1, 1);

                if (workExperience.StartDate > workExperience.EndDate)
                {
                    DateTime tempDate = workExperience.EndDate;
                    workExperience.EndDate   = workExperience.StartDate;
                    workExperience.StartDate = tempDate;
                }

                if (!string.IsNullOrEmpty(JobDescription))
                {
                    workExperience.JobDescription = this.JobDescription;
                }
                else
                {
                    workExperience.JobDescription = string.Empty;
                }
            }
            else
            {
                workExperience = WorkExperience.New();

                if (!string.IsNullOrEmpty(CompanyAreaCode))
                {
                    workExperience.CompanyAreaCode = this.CompanyAreaCode;
                }
                else
                {
                    workExperience.CompanyAreaCode = string.Empty;
                }

                workExperience.CompanyName = this.CompanyName;
                workExperience.EndDate     = new DateTime(this.EndDate, 1, 1);
                workExperience.StartDate   = new DateTime(this.StartDate, 1, 1);

                if (workExperience.StartDate > workExperience.EndDate)
                {
                    DateTime tempDate = workExperience.EndDate;
                    workExperience.EndDate   = workExperience.StartDate;
                    workExperience.StartDate = tempDate;
                }

                if (!string.IsNullOrEmpty(JobDescription))
                {
                    workExperience.JobDescription = this.JobDescription;
                }
                else
                {
                    workExperience.JobDescription = string.Empty;
                }

                workExperience.UserId = userId;
            }
            return(workExperience);
        }
Exemplo n.º 6
0
        public ActionResult Register(RegisterEditModel model)
        {
            InviteFriendSettings inviteFriendSettings = inviteFriendSettingsManager.Get();
            SystemMessageViewModel message;
            bool isContinue = InviteRegister(out message);
            if (!isContinue)
            {
                return Redirect(SiteUrls.Instance().SystemMessage(TempData, message));
            }
            if (!ModelState.IsValid)
                return View(model);
            User user = model.AsUser();

            //根据站点配置设置用户属性
            user.IsActivated = userSettings.AccountActivation == AccountActivation.Automatic;

            //尝试创建用户
            IMembershipService membershipService = DIContainer.Resolve<IMembershipService>();
            UserCreateStatus userCreateStatus = UserCreateStatus.UnknownFailure;
            membershipService.CreateUser(user, model.Password, out userCreateStatus);

            if (userCreateStatus != UserCreateStatus.Created)
            {
                switch (userCreateStatus)
                {
                    case UserCreateStatus.DisallowedUsername:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "不允许的用户名");
                        break;
                    case UserCreateStatus.DuplicateEmailAddress:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "重复的邮箱");
                        break;
                    case UserCreateStatus.DuplicateMobile:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "重复的手机号");
                        break;
                    case UserCreateStatus.DuplicateUsername:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "重复的用户名");
                        break;
                    case UserCreateStatus.InvalidPassword:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "不合法的密码");
                        break;
                    case UserCreateStatus.InvalidQuestionAnswer:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "不合法的问题答案");
                        break;
                    default:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "发生未知错误");
                        break;
                }
                model.Password = string.Empty;
                model.ConfirmPassword = string.Empty;
                return View(model);
            }

            UserProfileService userProfileService = new UserProfileService();
            UserProfile userProfile = UserProfile.New();
            userProfile.UserId = user.UserId;
            userProfileService.Create(userProfile);

            if (userSettings.EnableNotActivatedUsersToLogin || user.IsActivated)
                authenticationService.SignIn(user, false);

            if (Request.Cookies["invite"] != null)
            {
                string invite = Request.Cookies["invite"].Value;
                InvitationCode invitationCode = inviteFriendService.GetInvitationCodeEntity(invite);
                if (invitationCode != null)
                {
                    string errorMessage;
                    InviteFriendRecord inviteFriendRecord = new InviteFriendRecord
                    {
                        Code = invitationCode.Code,
                        DateCreated = DateTime.UtcNow,
                        InvitedUserId = user.UserId,
                        UserId = invitationCode.UserId
                    };
                    inviteFriendService.CreateInviteFriendRecord(inviteFriendRecord);
                    if (!invitationCode.IsMultiple)
                    {
                        bool isSuccess = MutualFollow(invitationCode, userService.GetFullUser(user.UserName), out errorMessage);
                        Response.Cookies.Remove("invite");
                        if (!isSuccess)
                        {
                            return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                            {
                                Title = "关注失败",
                                Body = errorMessage,
                                StatusMessageType = StatusMessageType.Hint
                            }));
                        }
                    }
                    else
                    {
                        User userFromDB = userService.GetFullUser(user.UserName);
                        if (userFromDB != null)
                        {
                            string token = Utility.EncryptTokenForInviteFriend(0.01, userFromDB.UserId);
                            return Redirect(SiteUrls.Instance().ConfirmFollow(token, Request.Cookies["invite"].Value));
                        }
                    }
                }

                //IUser userFromDB = userService.GetFullUser(model.UserName);
                //string token = null;
                //if (!userSettings.EnableNotActivatedUsersToLogin)
                //{
                //    token = Utility.EncryptTokenForInviteFriend(0.01, userFromDB.UserId);
                //    return Redirect(SiteUrls.Instance().ConfirmFollow(token));
                //}
                //User userFormDB = userService.GetFullUser(model.UserName);
                //string errorMessage;
                //AcceptInvitation(Request.Cookies["invite"].Value, userFormDB, out errorMessage);
            }

            return RegisterJumpByconfig(user);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 跳过第三方注册
        /// </summary>
        /// <returns></returns>
        public ActionResult JumpThirdRegister()
        {
            ThirdUser thirdUser = TempData.Get<ThirdUser>("thirdCurrentUser", null);
            TempData["thirdCurrentUser"] = thirdUser;
            if (thirdUser != null && new AccountBindingService().GetUserId(thirdUser.AccountTypeKey, thirdUser.Identification) > 0)
                return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Title = "重复绑定",
                    Body = "已经有网站帐号绑定过,不允许重复绑定第三方帐号",
                    StatusMessageType = StatusMessageType.Hint
                }));

            //创建用户,并且将对应用的用户与第三方账户绑定。
            UserCreateStatus userCreateStatus = UserCreateStatus.UnknownFailure;
            User user = Spacebuilder.Common.User.New();

            //生成用户名
            user.UserId = IdGenerator.Next();
            string userName = thirdUser.NickName;
            string thirUserName = "******" + userName;
            if (UserIdToUserNameDictionary.GetUserId(userName) <= 0)
                user.UserName = userName;
            else if (UserIdToUserNameDictionary.GetUserId(userName) <= 0)
                user.UserName = thirUserName;
            else
                user.UserName = user.UserId.ToString();

            //随机密码
            string password = string.Empty;
            string pwdchars = "abcdefghijklmnopqrstuvwxyz0123456789";
            int iRandNum;
            Random rnd = new Random();
            for (int i = 0; i < 6; i++)
            {
                iRandNum = rnd.Next(pwdchars.Length);
                password += pwdchars[iRandNum];
            }
            user.Password = password;

            // 和用户名一样
            user.NickName = user.UserName;
            user.AccountEmail = string.Empty;
            user.IsActivated = userSettings.AccountActivation == AccountActivation.Automatic;

            //创建用户
            membershipService.CreateUser(user, password, out userCreateStatus);
            if (userCreateStatus != UserCreateStatus.Created)
            {
                return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Title = "创建网站账号失败",
                    Body = "创建网站账号失败,请联系管理员",
                    StatusMessageType = StatusMessageType.Hint
                }));
            }

            //创建用户资料
            UserProfileService userProfileService = new UserProfileService();
            UserProfile userProfile = UserProfile.New();
            userProfile.UserId = user.UserId;
            userProfile.Gender = thirdUser.Gender;
            userProfileService.Create(userProfile);

            //让用户登录
            authenticationService.SignIn(user, false);

            //绑定帐号
            if (!string.IsNullOrEmpty(thirdUser.AccountTypeKey))
            {
                AccountBinding account = new AccountBinding();
                account.AccountTypeKey = thirdUser.AccountTypeKey;
                account.Identification = thirdUser.Identification;
                account.UserId = user.UserId;
                account.AccessToken = thirdUser.AccessToken;
                int expires_in = TempData.Get<int>("expires_in", 0);
                if (expires_in > 0)
                    account.ExpiredDate = DateTime.UtcNow.AddSeconds(expires_in);
                new AccountBindingService().CreateAccountBinding(account);
            }

            if (Request.Cookies != null)
            {
                if (Request.Cookies.Get("returnUrl") != null && !string.IsNullOrEmpty(Request.Cookies.Get("returnUrl").Value))
                {
                    string returnUrl = Request.Cookies.Get("returnUrl").Value;
                    Response.Cookies["returnUrl"].Expires = DateTime.Now;
                    return Redirect(Tunynet.Utilities.WebUtility.UrlDecode(returnUrl));
                }

            }

            //根据站点配置判断应该跳转到什么页面
            if (userSettings.MyHomePageAsSiteEntry)
                return Redirect(SiteUrls.Instance().MyHome(user.UserId));
            return Redirect(SiteUrls.Instance().SiteHome());
        }
Exemplo n.º 8
0
        public ActionResult ThirdRegister(ThirdRegisterEditModel model)
        {
            ThirdUser thirdUser = TempData.Get<ThirdUser>("thirdCurrentUser", null);
            TempData["thirdCurrentUser"] = thirdUser;
            if (!ModelState.IsValid)
                return View(model.CleanUp());
            if (thirdUser != null && new AccountBindingService().GetUserId(thirdUser.AccountTypeKey, thirdUser.Identification) > 0)
                return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Title = "重复绑定",
                    Body = "已经有网站帐号绑定过,不允许重复绑定第三方帐号",
                    StatusMessageType = StatusMessageType.Hint
                }));
            //数据通过验证,创建用户,并且将对应用的用户与第三方账户绑定。

            UserCreateStatus userCreateStatus = UserCreateStatus.UnknownFailure;
            User user = model.AsUser();

            user.IsActivated = userSettings.AccountActivation == AccountActivation.Automatic;

            membershipService.CreateUser(user, model.PassWord, out userCreateStatus);
            //如果没有创建成功
            if (userCreateStatus != UserCreateStatus.Created)
            {
                switch (userCreateStatus)
                {
                    case UserCreateStatus.DisallowedUsername:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "重复的用户名");
                        break;
                    case UserCreateStatus.DuplicateEmailAddress:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "重复的邮箱");
                        break;
                    case UserCreateStatus.DuplicateMobile:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "重复的手机号");
                        break;
                    case UserCreateStatus.DuplicateUsername:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "重复的用户名");
                        break;
                    case UserCreateStatus.InvalidPassword:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "不合法的密码");
                        break;
                    case UserCreateStatus.InvalidQuestionAnswer:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "不合法的问题答案");
                        break;
                    default:
                        ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "发生未知错误");
                        break;
                }
                return View(model.CleanUp());
            }

            // 处理头像
            //if (!string.IsNullOrEmpty(thirdUser.UserAvatarUrl))
            //{
            //    try
            //    {
            //        WebRequest webRequest = WebRequest.Create(thirdUser.UserAvatarUrl);
            //        HttpWebResponse httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
            //        Stream stream = httpWebResponse.GetResponseStream();

            //        bool isImage = httpWebResponse.ContentType.IndexOf("image") > -1;
            //        if (isImage && stream != null && stream.CanRead)
            //        {
            //            MemoryStream memoryStream = new MemoryStream();
            //            const int bufferLength = 1024;
            //            int actual;
            //            byte[] buffer = new byte[bufferLength];

            //            while ((actual = stream.Read(buffer, 0, bufferLength)) > 0)
            //            {
            //                memoryStream.Write(buffer, 0, actual);
            //            }

            //            userService.UploadOriginalAvatar(user.UserId, memoryStream);
            //            userService.CropAvatar(user.UserId, 100, 100, 0, 0);
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        ILogger logger = LoggerFactory.GetLogger();
            //        logger.Error(e, "第三方帐号登陆时,下载用户头像报错");
            //    }
            //}

            UserProfileService userProfileService = new UserProfileService();
            UserProfile userProfile = UserProfile.New();
            userProfile.UserId = user.UserId;
            userProfile.Gender = thirdUser.Gender;
            userProfileService.Create(userProfile);

            if (userSettings.EnableNotActivatedUsersToLogin || user.IsActivated)
                authenticationService.SignIn(user, false);

            if (!string.IsNullOrEmpty(thirdUser.AccountTypeKey))
            {
                //绑定帐号
                AccountBinding account = new AccountBinding();
                account.AccountTypeKey = thirdUser.AccountTypeKey;
                account.Identification = thirdUser.Identification;
                account.UserId = user.UserId;
                account.AccessToken = thirdUser.AccessToken;
                int expires_in = TempData.Get<int>("expires_in", 0);
                if (expires_in > 0)
                    account.ExpiredDate = DateTime.UtcNow.AddSeconds(expires_in);
                new AccountBindingService().CreateAccountBinding(account);

                var thirdAccountGetter = ThirdAccountGetterFactory.GetThirdAccountGetter(thirdUser.AccountTypeKey);
                if (model.FollowOfficial)
                {
                    //自动关注官方帐号
                    thirdAccountGetter.FollowOfficialMicroBlog(thirdUser.AccessToken, thirdUser.Identification);
                }
                if (model.ShareToFirend)
                {
                    //自动推送一条微博
                    //string siteName = DIContainer.Resolve<ISiteSettingsManager>().Get().SiteName;
                    //string content = string.Format(ResourceAccessor.GetString("AccountBinding_ShareToFirend"), thirdAccountGetter.AccountTypeName, siteName, SiteUrls.FullUrl(SiteUrls.Instance().SiteHome()));
                    string content = Request.Form.Get<string>("Content", string.Empty);
                    if (!string.IsNullOrEmpty(content))
                        thirdAccountGetter.CreateMicroBlog(thirdUser.AccessToken, content, thirdUser.Identification);
                }
            }

            if (Request.Cookies["invite"] != null)
            {
                string invite = Request.Cookies["invite"].Value;
                InvitationCode invitationCode = inviteFriendService.GetInvitationCodeEntity(invite);
                if (invitationCode != null)
                {
                    InviteFriendRecord inviteFriendRecord = new InviteFriendRecord
                    {
                        Code = invitationCode.Code,
                        DateCreated = DateTime.UtcNow,
                        InvitedUserId = user.UserId,
                        UserId = invitationCode.UserId
                    };
                    inviteFriendService.CreateInviteFriendRecord(inviteFriendRecord);
                    if (!invitationCode.IsMultiple)
                    {
                        Response.Cookies.Remove("invite");
                        string errorMessage;
                        bool isSuccess = MutualFollow(invitationCode, userService.GetFullUser(user.UserName), out errorMessage);
                        if (!isSuccess)
                        {
                            return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                            {
                                Title = "关注失败",
                                Body = errorMessage,
                                StatusMessageType = StatusMessageType.Hint
                            }));
                        }
                    }
                    else
                    {
                        User userFromDB = userService.GetFullUser(user.UserName);
                        if (userFromDB != null)
                        {
                            string token = Utility.EncryptTokenForInviteFriend(0.01, userFromDB.UserId);
                            return Redirect(SiteUrls.Instance().ConfirmFollow(token, Request.Cookies["invite"].Value));
                        }
                    }
                }
            }

            return RegisterJumpByconfig(user);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 转换为UserProfile用于数据库存储
        /// </summary>
        public UserProfile AsUserProfile(long userId)
        {
            UserProfile userProfile;
            if (UserId > 0)
            {
                UserProfileService userProfileService = new UserProfileService();
                userProfile = userProfileService.Get(UserId);
                userProfile.BirthdayType = this.BirthdayType;

                if (this.Gender == GenderType.FeMale)
                    userProfile.Gender = GenderType.FeMale;
                else if (this.Gender == GenderType.Male)
                    userProfile.Gender = GenderType.Male;

                else
                    userProfile.Gender = 0;

                if (this.BirthdayType == BirthdayType.LunarBirthday)
                {
                    ChinaDateTime cdt = new ChinaDateTime(LunarYear, LunarMonth, LunarDay);
                    userProfile.LunarBirthday = new DateTime(LunarYear, LunarMonth, LunarDay);
                    userProfile.Birthday = cdt.ToDateTime();

                }
                else
                {
                    if (Birthday != null)
                    {
                        ChinaDateTime cdt = new ChinaDateTime(Birthday.Value);
                        userProfile.Birthday = Birthday.Value;
                        userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                    }
                }

                if (!string.IsNullOrEmpty(Introduction))
                    userProfile.Introduction = this.Introduction;
                else
                    userProfile.Introduction = "";

                if (!string.IsNullOrEmpty(Email))
                    userProfile.Email = this.Email;
                else
                    userProfile.Email = "";

                if (!string.IsNullOrEmpty(Mobile))
                    userProfile.Mobile = this.Mobile;
                else
                    userProfile.Mobile = "";

                if (!string.IsNullOrEmpty(Msn))
                    userProfile.Msn = this.Msn;
                else
                    userProfile.Msn = "";

                if (!string.IsNullOrEmpty(NowAreaCode))
                    userProfile.NowAreaCode = this.NowAreaCode;
                else
                    userProfile.NowAreaCode = "";

                if (!string.IsNullOrEmpty(HomeAreaCode))
                    userProfile.HomeAreaCode = this.HomeAreaCode;
                else
                    userProfile.HomeAreaCode = "";

                if (!string.IsNullOrEmpty(QQ))
                    userProfile.QQ = this.QQ;
                else
                    userProfile.QQ = "";
            }
            else
            {
                userProfile = UserProfile.New();

                userProfile.BirthdayType = this.BirthdayType;

                if (this.Gender == GenderType.FeMale)
                    userProfile.Gender = GenderType.FeMale;
                else if (this.Gender == GenderType.Male)
                    userProfile.Gender = GenderType.FeMale;
                else
                    userProfile.Gender = 0;

                if (!string.IsNullOrEmpty(HomeAreaCode))
                    userProfile.HomeAreaCode = this.HomeAreaCode;
                else
                    userProfile.HomeAreaCode = "";

                if (!string.IsNullOrEmpty(NowAreaCode))
                    userProfile.NowAreaCode = this.NowAreaCode;
                else
                    userProfile.NowAreaCode = "";

                if (!string.IsNullOrEmpty(Email))
                    userProfile.Email = this.Email;
                else
                    userProfile.Email = "";

                if (!string.IsNullOrEmpty(Introduction))
                    userProfile.Introduction = this.Introduction;
                else
                    userProfile.Introduction = "";

                if (!string.IsNullOrEmpty(Mobile))
                    userProfile.Mobile = this.Mobile;
                else
                    userProfile.Mobile = "";

                if (!string.IsNullOrEmpty(Msn))
                    userProfile.Msn = this.Msn;
                else
                    userProfile.Msn = "";

                if (!string.IsNullOrEmpty(QQ))
                    userProfile.QQ = this.QQ;
                else
                    userProfile.QQ = "";

                if (Birthday != null)
                {
                    if (this.BirthdayType == BirthdayType.LunarBirthday)
                    {
                        ChinaDateTime cdt = new ChinaDateTime(LunarYear, LunarMonth, LunarDay);
                        userProfile.LunarBirthday = new DateTime(LunarYear, LunarMonth, LunarDay);
                        userProfile.Birthday = cdt.ToDateTime();

                    }
                    else
                    {
                        ChinaDateTime cdt = new ChinaDateTime(Birthday.Value);
                        userProfile.Birthday = Birthday.Value;
                        userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                    }
                }
                else
                {
                    ChinaDateTime cdt = new ChinaDateTime(DateTime.UtcNow);
                    userProfile.Birthday = DateTime.UtcNow;
                    userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                }

                userProfile.UserId = userId;

            }
            return userProfile;
        }
Exemplo n.º 10
0
        /// <summary>
        /// 转换为UserProfile用于数据库存储
        /// </summary>
        public UserProfile AsUserProfile(long userId)
        {
            UserProfile userProfile;

            if (UserId > 0)
            {
                UserProfileService userProfileService = new UserProfileService();
                userProfile = userProfileService.Get(UserId);
                userProfile.BirthdayType = this.BirthdayType;

                if (this.Gender == GenderType.FeMale)
                {
                    userProfile.Gender = GenderType.FeMale;
                }
                else if (this.Gender == GenderType.Male)
                {
                    userProfile.Gender = GenderType.Male;
                }

                else
                {
                    userProfile.Gender = 0;
                }

                if (this.BirthdayType == BirthdayType.LunarBirthday)
                {
                    ChinaDateTime cdt = new ChinaDateTime(LunarYear, LunarMonth, LunarDay);
                    userProfile.LunarBirthday = new DateTime(LunarYear, LunarMonth, LunarDay);
                    userProfile.Birthday      = cdt.ToDateTime();
                }
                else
                {
                    if (Birthday != null)
                    {
                        ChinaDateTime cdt = new ChinaDateTime(Birthday.Value);
                        userProfile.Birthday      = Birthday.Value;
                        userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                    }
                }

                if (!string.IsNullOrEmpty(Introduction))
                {
                    userProfile.Introduction = this.Introduction;
                }
                else
                {
                    userProfile.Introduction = "";
                }

                if (!string.IsNullOrEmpty(Email))
                {
                    userProfile.Email = this.Email;
                }
                else
                {
                    userProfile.Email = "";
                }

                if (!string.IsNullOrEmpty(Mobile))
                {
                    userProfile.Mobile = this.Mobile;
                }
                else
                {
                    userProfile.Mobile = "";
                }

                if (!string.IsNullOrEmpty(Msn))
                {
                    userProfile.Msn = this.Msn;
                }
                else
                {
                    userProfile.Msn = "";
                }

                if (!string.IsNullOrEmpty(NowAreaCode))
                {
                    userProfile.NowAreaCode = this.NowAreaCode;
                }
                else
                {
                    userProfile.NowAreaCode = "";
                }

                if (!string.IsNullOrEmpty(HomeAreaCode))
                {
                    userProfile.HomeAreaCode = this.HomeAreaCode;
                }
                else
                {
                    userProfile.HomeAreaCode = "";
                }

                if (!string.IsNullOrEmpty(QQ))
                {
                    userProfile.QQ = this.QQ;
                }
                else
                {
                    userProfile.QQ = "";
                }
            }
            else
            {
                userProfile = UserProfile.New();

                userProfile.BirthdayType = this.BirthdayType;

                if (this.Gender == GenderType.FeMale)
                {
                    userProfile.Gender = GenderType.FeMale;
                }
                else if (this.Gender == GenderType.Male)
                {
                    userProfile.Gender = GenderType.FeMale;
                }
                else
                {
                    userProfile.Gender = 0;
                }

                if (!string.IsNullOrEmpty(HomeAreaCode))
                {
                    userProfile.HomeAreaCode = this.HomeAreaCode;
                }
                else
                {
                    userProfile.HomeAreaCode = "";
                }

                if (!string.IsNullOrEmpty(NowAreaCode))
                {
                    userProfile.NowAreaCode = this.NowAreaCode;
                }
                else
                {
                    userProfile.NowAreaCode = "";
                }

                if (!string.IsNullOrEmpty(Email))
                {
                    userProfile.Email = this.Email;
                }
                else
                {
                    userProfile.Email = "";
                }

                if (!string.IsNullOrEmpty(Introduction))
                {
                    userProfile.Introduction = this.Introduction;
                }
                else
                {
                    userProfile.Introduction = "";
                }

                if (!string.IsNullOrEmpty(Mobile))
                {
                    userProfile.Mobile = this.Mobile;
                }
                else
                {
                    userProfile.Mobile = "";
                }

                if (!string.IsNullOrEmpty(Msn))
                {
                    userProfile.Msn = this.Msn;
                }
                else
                {
                    userProfile.Msn = "";
                }

                if (!string.IsNullOrEmpty(QQ))
                {
                    userProfile.QQ = this.QQ;
                }
                else
                {
                    userProfile.QQ = "";
                }

                if (Birthday != null)
                {
                    if (this.BirthdayType == BirthdayType.LunarBirthday)
                    {
                        ChinaDateTime cdt = new ChinaDateTime(LunarYear, LunarMonth, LunarDay);
                        userProfile.LunarBirthday = new DateTime(LunarYear, LunarMonth, LunarDay);
                        userProfile.Birthday      = cdt.ToDateTime();
                    }
                    else
                    {
                        ChinaDateTime cdt = new ChinaDateTime(Birthday.Value);
                        userProfile.Birthday      = Birthday.Value;
                        userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                    }
                }
                else
                {
                    ChinaDateTime cdt = new ChinaDateTime(DateTime.UtcNow);
                    userProfile.Birthday      = DateTime.UtcNow;
                    userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                }

                userProfile.UserId = userId;
            }
            return(userProfile);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 转换为EducationExperience用于数据库存储
        /// </summary>
        public EducationExperience AsEducationExperience(long userId)
        {
            EducationExperience educationExperience;
            if (Id > 0)
            {
                UserProfileService userProfileService = new UserProfileService();
                educationExperience = userProfileService.GetEducationExperience(Id, userId);
                educationExperience.Degree = this.Degree;
                educationExperience.School = this.School;
                educationExperience.StartYear = this.StartYear;

                if (!string.IsNullOrEmpty(Department))
                    educationExperience.Department = this.Department;
                else
                    educationExperience.Department = string.Empty;

            }
            else
            {
                educationExperience = EducationExperience.New();
                educationExperience.Degree = this.Degree;
                educationExperience.School = this.School;
                educationExperience.StartYear = this.StartYear;

                if (!string.IsNullOrEmpty(Department))
                    educationExperience.Department = this.Department;
                else
                    educationExperience.Department = string.Empty;

                educationExperience.UserId = userId;
            }
            return educationExperience;
        }