예제 #1
0
        /// <summary>
        ///账号密码登录
        /// </summary>
        /// <returns></returns>
        public JsonResult <Result <dynamic> > GetLoginByUserName(string openId = "", string userName = "", string password = "", string nickName = "")
        {
            if (!string.IsNullOrEmpty(openId) && !string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
            {
                MemberInfo member = null;

                try
                {
                    member = ServiceProvider.Instance <IMemberService> .Create.Login(userName, password);
                }
                catch (Exception ex)
                {
                    return(Json(ErrorResult <dynamic>(ex.Message)));
                }
                if (member == null)
                {
                    return(Json(ErrorResult <dynamic>("用户名或密码错误")));
                }
                else
                {
                    if (member != null)
                    {
                        //如果不是一键登录的 则绑定openId
                        if (!string.IsNullOrEmpty(openId))
                        {
                            MemberOpenIdInfo memberOpenIdInfo = new MemberOpenIdInfo()
                            {
                                UserId          = member.Id,
                                OpenId          = openId,
                                ServiceProvider = SmallProgServiceProvider,
                                AppIdType       = MemberOpenIdInfo.AppIdTypeEnum.Normal,
                                UnionId         = string.Empty
                            };
                            MemberApplication.UpdateOpenIdBindMember(memberOpenIdInfo);
                        }

                        string memberId = UserCookieEncryptHelper.Encrypt(member.Id, CookieKeysCollection.USERROLE_USER);
                        return(GetMember(member, openId));
                    }
                }
            }
            return(Json(ErrorResult <dynamic>(string.Empty)));
        }