前边说过主框架除了对插件提供宿主的外另外主要就是提供用户管理功能这次做用户注册和登录功能:
整个用户操作WCF服务都在WSMain.SVC服务中主要提供了如下地思路方法:
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public WSMain
{
[OperationContract]
public bool Login( userName, passWord)
{
MainBLL bll = MainBLL;
bll.Login(userName,passWord);
}
[OperationContract]
public Regiest(UserInfo userInfo)
{
MainBLL bll = MainBLL;
bll.Regiest(userInfo);
}
[OperationContract]
public UserInfo GetUserInfo( userName)
{
UserInfo result = UserInfo;
result;
}
[OperationContract]
public List<UserRelaInfo> GetFriends( userName)
{
List<UserRelaInfo> result = List<UserRelaInfo>;
MainBLL bll = MainBLL;
result = bll.GetFriends(userName);
result;
}
[OperationContract]
public bool UpDateLocalStyle( userRelationId, localStyle)
{
bool result = true;
MainBLL bll = MainBLL;
bll.UpDateLocalStyle(userRelationId, localStyle);
result;
}
// Add more operations here and mark them with [OperationContract]
}
具体实现界面请参照牛人篇文章:http://www.cnblogs.com/RChen/archive/2008/07/05/1236046.html
这是服务器端服务我们看看客户端:
private void UserRegion( userName, userMail, passWord)
{
WSMain.UserInfo userInfo = WSMain.UserInfo;
passWord = MD5CryptoServiceProvider.GetMd5String(passWord);
passWord = MD5CryptoServiceProvider.GetMd5String(userName + passWord);
//
userInfo.UserName = userName;
userInfo.PassWord = passWord;
userInfo.EMail = userMail;
//
Uri uri = .Windows.Browser.HtmlPage.Document.DocumentUri;
host = uri.AbsoluteUri;
host = host.Sub(0, host.Length - uri.LocalPath.Length);
servicePath = "/Services/WSMain.svc";
serviceUri = host + servicePath;
WSMainClient wsMain = WSMainClient( .ServiceModel.BasicHttpBinding, .ServiceModel.EndpoAddress(serviceUri));
wsMain.RegiestCompleted (o, ev) =>
{
(ev.Error null)
{
result = ev.Result;
(result "True")
{
//设定用户信息
PublicUnit.UserInfo.UserName = userName;
PublicUnit.UserInfo.UsereMail = userMail;
PublicUnit.UserInfo.IsLogined = true;
//关闭当前窗口
Close;
}
{
this.txtMesage.Text = result;
}
}
};
wsMain.RegiestAsync(userInfo);
}
}
这是客户端思路方法其中用户密码使用md5进行离散然后再和用户名相加进行第 2次离散这样出来结果基本不可能被现有md5查询网站WebSite查询出来密码
然后服务器端注册思路方法本来可以返回bool类型但是有点偷懒就返回了个串当串是”True”时候表示注册成功其他表示失败返回是失败原因
注册成功的后就设定个静态变量这个静态变量就是整个宿主登陆用户
然后关闭窗口至此用户注册完成其实大家可以看到当用户注册成功的后就进入了自动登陆状态整个主界面上输入用户密码登陆就隐藏了换成了查看用户信息这个是使用用户登陆事件:
public PublicUnit
{
public PluginConfigFile = "WindCloud.Config.xml";
public MainUser UserInfo = MainUser;
}
public MainUser : UserInfo
{
public delegate void Longined(Object sender, bool isLogined);
public event Longined _disibledevent= true;
}
{
//登录失败
MessageBox.Show("用户不存在或密码!请重新输入"n如果是未注册用户请先注册", "提示", MessageBoxButton.OK);
}
}
};
wsMain.LoginAsync(userName, passWord);
这就是整个用户登陆也是使用设定用户登陆状态是否存在
至此整个用户注册和登录完成
欢迎对开源项目有兴趣朋友加入这个项目组招收开源开发人员
预览:www.cuface.cn (SilverLight RC0)
最新评论