Exemplo n.º 1
0
        public async Task<HttpResponseMessage> PostInitialize([FromBody]DualParameter postParameter)
        {
            string openid = postParameter.openID;
            Guid uuid = postParameter.uuid;
            if (string.IsNullOrEmpty(openid) && uuid == Guid.Empty)
            {
                return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using (UserRepository userRepository = new UserRepository())
            {
                userinfo = await userRepository.GetUserInfoByUuidAsync(uuid);
                if (userinfo == null)
                {
                    return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
                }
                var userUuid = await userRepository.GetUserUuidByOpenid(openid);

                VisitBetweenUser newVisitor = new VisitBetweenUser() { UserGuest_uuid = userUuid, UserHost_uuid = uuid, VisitTime = DateTime.Now };
                await userRepository.AddVisitBetweenUser(newVisitor);

                userinfo.NumOfContacts = await userRepository.GetUserContactNumber(uuid);
                userinfo.NumOfVisitor = await userRepository.GetUserVisitorNumber(uuid);
                userinfo.NumOfFavorite = await userRepository.GetuserFavoriteNumber(uuid);
                userinfo.IsContact = await userRepository.IsUserContact(userUuid, uuid);
                userinfo.IsFavorite = (await userRepository.IsUserFavorite(userUuid, uuid)).ToString();
                return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, userinfo, HttpStatusCode.OK, customStatus.Success);
            }
        }
Exemplo n.º 2
0
        public async Task<HttpResponseMessage> PostInitialize([FromBody]LoginParameter postParameter)
        {
            string openid = postParameter.openID;
            if (string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using (UserRepository userRepository = new UserRepository())
            {
                userinfo = await userRepository.GetUserInfoByOpenid(openid);
                if (userinfo == null)
                {
                    return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
                }
                userinfo.NumOfContacts = await userRepository.GetUserContactNumber(userinfo.uuid);
                userinfo.NumOfVisitor = await userRepository.GetUserVisitorNumber(userinfo.uuid);
                userinfo.NumOfFavorite = await userRepository.GetuserFavoriteNumber(userinfo.uuid);
                using(SystemRepository systemRepository = new SystemRepository())
                {
                    userinfo.Hometown = await systemRepository.GetShortAddress(userinfo.HometownProvince,userinfo.HometownCity);
                }
                return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, userinfo, HttpStatusCode.OK, customStatus.Success);
            }


        }
Exemplo n.º 3
0
        public static async Task<bool> SaveUserInfo(ComplementParameter complementParameter, pre_register preRegister)
        {
            bool saveresult = false;
            bool createresult = false;
            UserInfoRedis userinfoRedis = await GetUserInfoRedisByOpenid(complementParameter.openID);
            UserInfo userinfo = null;
            using (UserRepository userRepository = new UserRepository())
            {
                userinfo = await userRepository.GetUserInfoByOpenid(complementParameter.openID);
                if (userinfo == null)
                {
                    userinfo = new UserInfo()
                    {
                        AccountEmail = preRegister.accountemail,
                        Password = preRegister.password,
                        CreateTime = preRegister.createtime,
                        Name = preRegister.name,
                        Gender = userinfoRedis.Sex,
                        Phone = preRegister.accountemail.Substring(0, 11),
                        IsBusiness = preRegister.validate
                    };
                    createresult = true;
                }
                else
                {
                    userinfo.Name = complementParameter.name;
                    userinfo.Gender = complementParameter.Gender;
                }
                await CheckUserInfoPhoto(userinfo, userinfoRedis);

                userinfo.Unit = complementParameter.university;
                userinfo.Faculty = complementParameter.faculty;
                userinfo.ResearchFieldId = complementParameter.researchFieldId;
                userinfo.Degree = complementParameter.degree;
                if (userinfo.IsBusiness==2)
                    userinfo.Enrollment = complementParameter.enrollment;
                if (userinfo.IsBusiness == 0 && !string.IsNullOrEmpty(complementParameter.position))
                    userinfo.Position = complementParameter.position;
                userinfo.Province = complementParameter.province;
                userinfo.City = complementParameter.city;
                userinfo.Birthday = complementParameter.birthday;
                userinfo.HometownProvince = complementParameter.hometownProvince;
                userinfo.HometownCity = complementParameter.hometownCity;
                userinfo.Position = complementParameter.position;
                saveresult = await userRepository.SaveUserInfo(userinfo);

                if (saveresult & createresult)
                    await userRepository.SaveUserOpenid(userinfo.uuid, userinfoRedis.Openid, userinfoRedis.Unionid);
            }
            return saveresult;
        }
Exemplo n.º 4
0
 public static async Task<bool> CheckUserInfoPhoto(UserInfo userinfo, UserInfoRedis userinfoRedis)
 {
     bool result = false;
     if(string.IsNullOrEmpty(userinfo.Photo) || userinfo.Photo == "pic/header/HeaderDefault.jpg")
     {
         userinfo.Photo = WebApiHelper.UploadHeadPic(userinfoRedis.HeadImageUrl.Substring(0, userinfoRedis.HeadImageUrl.LastIndexOf("/0")));
         result = true;
     }
     if(!result && await WXAuthHelper.IsTester(userinfoRedis.Openid))
     {
         userinfo.Photo = WebApiHelper.UploadHeadPic(userinfoRedis.HeadImageUrl.Substring(0, userinfoRedis.HeadImageUrl.LastIndexOf("/0")));
         result = true;
     }
     return result;
 }
Exemplo n.º 5
0
        public async Task<HttpResponseMessage> PostValidationCode([FromBody]RegisterParameter registerParam)
        {
            string sNewAccount = registerParam.account;
            string validationCode = (new Random()).Next(1000, 9999).ToString();
            string openid = registerParam.openID;

            //对应openid从redis取出验证码 若没有 生成验证码 存入redis **20分钟有效
            var userinfoRedis = await UserInfoControllerHelper.GetUserInfoRedisByOpenid(openid);
            //注册测试用的白名单
            if(string.IsNullOrEmpty(userinfoRedis.PreRegisterValidationCode) || await CommonLib.Weixin.User.WXAuthHelper.IsTester(openid))
            {
                await UserInfoControllerHelper.SaveUserPreRegisterToRedis(openid, preRegisterValidationCode: validationCode);
            }
            else
            {
                validationCode = userinfoRedis.PreRegisterValidationCode;
            }

            if(string.IsNullOrEmpty(sNewAccount) || string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            if(!sNewAccount.Contains("@"))
                sNewAccount += "@phone.51science.cn";
            using(UserRepository userRepository = new UserRepository())
            {
                userinfo = await userRepository.GetUserInfoByAccount(sNewAccount);
                //注册测试用的白名单
                if(userinfo != null && !await CommonLib.Weixin.User.WXAuthHelper.IsTester(openid))
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.AccountExist);
                else
                {
                    WebApiHelper.SendValidStringSMS(validationCode, sNewAccount.Substring(0, 11));

                    //向redis里存入手机号 防止故意验证失败后又改其他手机号注册 向redis里存入验证次数
                    await UserInfoControllerHelper.SaveUserPreRegisterToRedis(openid, preRegisterAccount: sNewAccount, preRegisterTryTimes: "10");

                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Success);
                }
            }
        }
Exemplo n.º 6
0
        public async Task<HttpResponseMessage> PostInitialize([FromBody]LoginParameter loginParameter)
        {
            string openid = loginParameter.openID;
            if (string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(loginParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using (UserRepository userRepository = new UserRepository())
            {
                userinfo = await userRepository.GetUserInfoByOpenid(openid);
                if (userinfo == null)
                {
                    return WebApiHelper.HttpRMtoJson(loginParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
                }
                userinfo.NumOfContacts = await userRepository.GetUserContactNumber(userinfo.uuid);
                userinfo.NumOfBeenTo = await userRepository.GetUserBeenToNumber(userinfo.uuid);
                userinfo.NumOfFavorite = await userRepository.GetuserFavoriteNumber(userinfo.uuid);
                
                return WebApiHelper.HttpRMtoJson(userinfo, HttpStatusCode.OK, customStatus.Success);
            }


        }
Exemplo n.º 7
0
        public async Task<HttpResponseMessage> PostUserLoginAccountPassword([FromBody]LoginParameter userlogin)
        {
            string account = userlogin.account;
            string password = userlogin.password;
            string openid = userlogin.openID;
            if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(openid))
                return WebApiHelper.HttpRMtoJson(userlogin.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
            //[email protected]
            if (!account.Contains("@"))
                account += "@phone.51science.cn";
            password = Encryption.EncryptMD5(userlogin.password);
            using (UserRepository userRepository = new UserRepository())
            {
                userinfo = await userRepository.GetUserInfoByAccountPassword(account, password);
                if (userinfo != null)
                {
                    if (userinfo.Status == 1)
                        return WebApiHelper.HttpRMtoJson(userlogin.jsonpCallback, userinfo, HttpStatusCode.OK, customStatus.Forbidden);
                    else
                    {
                        if (userinfo.IsLogin == 0)
                        {
                            userinfo.IsLogin = 1;
                            userinfo.LastLogin = DateTime.MinValue;
                        }
                        var userinfoRedis = await UserInfoControllerHelper.GetUserInfoRedisByOpenid(openid);

                        if (await UserInfoControllerHelper.CheckUserInfoPhoto(userinfo, userinfoRedis))
                        {
                            //photo已更新为微信头像
                        }
                        int clIsBusiness = userinfo.IsBusiness ?? 0;
                        //性别取自微信
                        int clGender = string.IsNullOrEmpty(userinfoRedis.Sex) ? 0 : int.Parse(userinfoRedis.Sex);
                        long clResearchFieldID = userinfo.ResearchFieldId ?? 0;
                        if (await ComplexLocationManager.UpdateComplexLocationAsync(openid, clIsBusiness, clGender, clResearchFieldID))
                        {
                            //位置索引添加供筛选字段
                            try
                            {
                                BKLogger.LogInfoAsync(typeof(LoginController), "记录位置信息:"
                                    + userinfo.Name
                                    + userinfo.uuid.ToString()
                                    + userinfo.IsBusiness 
                                    + userinfo.Gender 
                                    + userinfo.ResearchFieldId + " | "
                                    + clIsBusiness + clGender + clResearchFieldID);
                            }
                            catch (Exception ex)
                            {

                            }
                        }
                        if (await userRepository.SaveUserOpenid(userinfo.uuid, openid, userinfoRedis.Unionid))
                        {
                            userinfo.Gender = userinfoRedis.Sex;
                            return WebApiHelper.HttpRMtoJson(userlogin.jsonpCallback, userinfo, HttpStatusCode.OK, customStatus.Success);
                        }
                        else
                            return WebApiHelper.HttpRMtoJson(userlogin.jsonpCallback, userinfo, HttpStatusCode.OK, customStatus.Fail);

                    }

                }
                else
                {
                    userinfo = await userRepository.GetUserInfoByAccount(account);
                    if (userinfo != null)
                        return WebApiHelper.HttpRMtoJson(userlogin.jsonpCallback, null, HttpStatusCode.OK, customStatus.WrongPassowrd);
                    else
                        return WebApiHelper.HttpRMtoJson(userlogin.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
                }
            }
        }
Exemplo n.º 8
0
        public async Task<HttpResponseMessage> PostResetPassword([FromBody]PasswordParameter postParameter)
        {
            string openid = postParameter.openID;
            string old = postParameter.oldPassword;
            string newp = postParameter.newPassword;

            if (string.IsNullOrEmpty(openid)|| string.IsNullOrEmpty(old) || string.IsNullOrEmpty(newp))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using (UserRepository userRepository = new UserRepository())
            {
                userinfo = await userRepository.GetUserInfoByOpenid(openid);
                if (userinfo == null)
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound);
                else
                {
                    if (userinfo.AccountEmail.Contains("@phone.51science.cn"))
                        return WebApiHelper.HttpRMtoJson(userinfo.AccountEmail.Replace("@phone.51science.cn", ""), HttpStatusCode.OK, customStatus.Success);
                    else
                        return WebApiHelper.HttpRMtoJson(userinfo.AccountEmail, HttpStatusCode.OK, customStatus.Success);
                }
            }
        }
Exemplo n.º 9
0
        public async Task<HttpResponseMessage> PostUserLoginResetPassword([FromBody]RegisterParameter registerParam)
        {
            string sNewAccount = registerParam.account;
            string validationCode = registerParam.validationCode;
            string password = Encryption.EncryptMD5(registerParam.password);
            string openid = registerParam.openID;

            if (string.IsNullOrEmpty(sNewAccount) || string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(validationCode) || password == Encryption.EncryptMD5(""))
            {
                return WebApiHelper.HttpRMtoJson(registerParam.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            if (!sNewAccount.Contains("@"))
                sNewAccount += "@phone.51science.cn";

            using (UserRepository userRepository = new UserRepository())
            {
                userinfo = await userRepository.GetUserInfoByAccount(sNewAccount);
            }
            if (userinfo == null)
                return WebApiHelper.HttpRMtoJson(registerParam.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound);
            else
            {
                var preRegisterRedis = await UserInfoControllerHelper.GetUserInfoRedisByOpenid(openid);

                string preRegisterAccount = preRegisterRedis.PreRegisterAccount;
                string preRegisterValidationCode = preRegisterRedis.PreRegisterValidationCode;

                int preRegisterTryTimes = 0;
                int.TryParse(preRegisterRedis.PreRegisterTryTimes, out preRegisterTryTimes);

                if (string.IsNullOrEmpty(preRegisterAccount) || sNewAccount != preRegisterAccount)
                {
                    await UserInfoControllerHelper.SaveUserPreRegisterToRedis(openid, preRegisterValidationCode: "");
                    preRegisterValidationCode = "";
                }

                if (!string.IsNullOrEmpty(preRegisterValidationCode))
                {
                    if (preRegisterTryTimes > 0)
                    {
                        await UserInfoControllerHelper.SaveUserPreRegisterToRedis(openid, preRegisterTryTimes: (preRegisterTryTimes - 1).ToString());
                    }
                    else
                    {
                        await UserInfoControllerHelper.SaveUserPreRegisterToRedis(openid, "", "", "");
                        return WebApiHelper.HttpRMtoJson(registerParam.jsonpCallback, null, HttpStatusCode.OK, customStatus.Forbidden);
                    }

                    if (validationCode != preRegisterValidationCode)
                    {
                        return WebApiHelper.HttpRMtoJson(registerParam.jsonpCallback, null, HttpStatusCode.OK, customStatus.ErrorValidationCode);
                    }
                }
                else
                {
                    return WebApiHelper.HttpRMtoJson(registerParam.jsonpCallback, null, HttpStatusCode.OK, customStatus.NoValidationCode);
                }
                bool result = false;
                using (UserRepository userRepository = new UserRepository())
                {
                    result = await userRepository.UpdateUserinfoPassword(sNewAccount, password);
                }
                if (result)
                    return WebApiHelper.HttpRMtoJson(registerParam.jsonpCallback, null, HttpStatusCode.OK, customStatus.Success);
                else
                    return WebApiHelper.HttpRMtoJson(registerParam.jsonpCallback, null, HttpStatusCode.OK, customStatus.Fail);
            }
        }
Exemplo n.º 10
0
        public async Task<HttpResponseMessage> PostRegister([FromBody]RegisterParameter registerParam)
        {
            string sNewAccount = registerParam.account;
            string validationCode = registerParam.validationCode;
            string name = registerParam.name;
            string password = Encryption.EncryptMD5(registerParam.password);
            string openid = registerParam.openID;

            if(string.IsNullOrEmpty(sNewAccount) || string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(validationCode) || string.IsNullOrEmpty(name) || password == Encryption.EncryptMD5(""))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            if(!sNewAccount.Contains("@"))
                sNewAccount += "@phone.51science.cn";

            using(UserRepository userRepository = new UserRepository())
            {
                userinfo = await userRepository.GetUserInfoByAccount(sNewAccount);
                //注册测试用的白名单
                if(userinfo != null && !await CommonLib.Weixin.User.WXAuthHelper.IsTester(openid))
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.AccountExist);
                else
                {
                    // 从redis里取出手机号、验证码 防止故意验证失败后又改其他手机号注册 从redis里取出验证次数
                    var preRegisterRedis = await UserInfoControllerHelper.GetUserInfoRedisByOpenid(openid);

                    string preRegisterAccount = preRegisterRedis.PreRegisterAccount;
                    string preRegisterValidationCode = preRegisterRedis.PreRegisterValidationCode;

                    int preRegisterTryTimes = 0;
                    int.TryParse(preRegisterRedis.PreRegisterTryTimes, out preRegisterTryTimes);

                    if(string.IsNullOrEmpty(preRegisterAccount) || sNewAccount != preRegisterAccount)
                    {
                        await UserInfoControllerHelper.SaveUserPreRegisterToRedis(openid, preRegisterValidationCode: "");
                        preRegisterValidationCode = "";
                    }

                    if(!string.IsNullOrEmpty(preRegisterValidationCode))
                    {
                        if(preRegisterTryTimes > 0)
                        {
                            await UserInfoControllerHelper.SaveUserPreRegisterToRedis(openid, preRegisterTryTimes: (preRegisterTryTimes - 1).ToString());
                        }
                        else
                        {
                            await UserInfoControllerHelper.SaveUserPreRegisterToRedis(openid, "", "", "");
                            return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Forbidden);
                        }

                        if(validationCode != preRegisterValidationCode)
                        {
                            return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Fail);
                        }
                    }
                    else
                    {
                        return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound);
                    }
                    await userRepository.SavePreRegister(sNewAccount, name, password,2, openid);
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Success);
                }
            }

        }
Exemplo n.º 11
0
        public async Task<HttpResponseMessage> PostComplement([FromBody]ComplementParameter registerParam, [FromUri]string type)
        {
            string openid = registerParam.openID;
            string university = registerParam.university;
            string faculty = registerParam.faculty;
            int researchFieldId = registerParam.researchFieldId;
            short degree = registerParam.degree;
            short enrollment = registerParam.enrollment;
            string gender = registerParam.Gender;
            string name = registerParam.name;
            string position = registerParam.position;
            short isBusiness = registerParam.isBusiness;
            if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(university) || string.IsNullOrEmpty(faculty) || researchFieldId == 0 || string.IsNullOrEmpty(gender) || string.IsNullOrEmpty(name))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }
            if (string.IsNullOrEmpty(position) && isBusiness == 0)
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }
            if (isBusiness == 2 && enrollment == 0)
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            var preRegisterRedis = await UserInfoControllerHelper.GetUserInfoRedisByOpenid(openid);
            string preRegisterAccount = preRegisterRedis.PreRegisterAccount;
            pre_register preRegister = null;

            if (type != "update")
            {
                using (UserRepository userRepository = new UserRepository())
                {
                    userinfo = await userRepository.GetUserInfoByAccount(preRegisterAccount);
                    preRegister = await userRepository.GetPreRegisterByOpenid(openid);
                }
                if (userinfo != null)
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.AccountExist);
                if (preRegister == null)
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound);
            }

            //更新数据库的userinfo
            bool result = await UserInfoControllerHelper.SaveUserInfo(registerParam, preRegister);
            if (result)
            {
                //更新redis的性别
                UserInfoRedis redisUser = new UserInfoRedis();
                redisUser.Openid = openid;
                redisUser.Sex = gender;
                await RedisManager.SaveObjectAsync(redisUser);

                using (UserRepository userRepository = new UserRepository())
                {
                    userinfo = await userRepository.GetUserInfoByOpenid(openid);
                }

                if (await ComplexLocationManager.UpdateComplexLocationAsync(openid, userinfo.IsBusiness ?? 0, int.Parse(userinfo.Gender), userinfo.ResearchFieldId ?? 0))
                {
                    //位置索引添加供筛选字段
                }

                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Success);
            }
            else
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Fail);
            }
        }
Exemplo n.º 12
0
        public async Task<HttpResponseMessage> PostInitialize([FromBody]RegisterParameter registerParam, [FromUri]string type)
        {
            string openid = registerParam.openID;
            if(string.IsNullOrEmpty(openid))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }
            pre_register prereg = null;
            using(UserRepository userRepository = new UserRepository())
            {
                var userinfoRedis = await BK.CommonLib.Weixin.User.WXAuthHelper.GetUserInfoByOPenId(openid);

                if(type != "update")
                {
                    prereg = await userRepository.GetPreRegisterByOpenid(openid);

                    if(prereg == null)
                    {
                        return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound);
                    }
                    userinfo = new UserInfo() {
                        Photo = userinfoRedis.HeadImageUrl.Substring(0, userinfoRedis.HeadImageUrl.LastIndexOf("/0")) + "/96",
                        Name = prereg.name,
                        Gender = userinfoRedis.Sex,
                    };
                }
                else
                {
                    userinfo = await userRepository.GetUserInfoByOpenid(openid);
                    userinfo.Gender = userinfoRedis.Sex;
                }

                return WebApiHelper.HttpRMtoJson(userinfo, HttpStatusCode.OK, customStatus.Success);

            }
        }