示例#1
0
 void OnUploadFinished(object sender, bool suc)
 {
     if (suc)
     {
         AtState.SaveCookie("FileTransDemo", _fl.Data);
     }
 }
示例#2
0
        /// <summary>
        /// 更新好友列表,默认超过10小时需要刷新
        /// </summary>
        /// <returns></returns>
        public static async Task Refresh()
        {
            if (!NeedRefresh())
            {
                return;
            }

            // 暂时取所有,后续增加好友功能
            var tbl = await new UnaryRpc(
                "cm",
                "Da.Query",
                "select id,name,phone,sex,(case photo when '' then 'photo/profilephoto.jpg' else photo end) as photo, mtime from cm_user"
                ).Call <Table <ChatMember> >();

            // 将新列表缓存到本地库
            AtState.Exec("delete from ChatMember");
            if (tbl != null && tbl.Count > 0)
            {
                foreach (var r in tbl)
                {
                    r.IsAdded = true;
                }
                await AtState.BatchSave(tbl, false);
            }

            // 记录刷新时间
            AtState.SaveCookie(_refreshKey, Kit.Now.ToString());
        }
示例#3
0
        /// <summary>
        /// 登录
        /// </summary>
        async void OnLogin()
        {
            string phone  = _tbPhone.Text.Trim();
            bool   isCode = _tbPwd.Visibility == Visibility.Collapsed;
            string txt    = isCode ? _tbCode.Text.Trim() : _tbPwd.Password;

            if (string.IsNullOrEmpty(phone))
            {
                _tbPhone.Focus(FocusState.Programmatic);
            }
            else if (IsPhoneError())
            {
            }
            else if (string.IsNullOrEmpty(txt))
            {
                if (isCode)
                {
                    _tbCode.Focus(FocusState.Programmatic);
                }
                else
                {
                    _tbPwd.Focus(FocusState.Programmatic);
                }
            }
            else
            {
                LoginPanel.Visibility = Visibility.Collapsed;
                InfoPanel.Visibility  = Visibility.Visible;
                try
                {
                    string      pwd = null;
                    LoginResult result;
                    if (isCode)
                    {
                        // 验证码登录
                        result = await AtCm.LoginByCode(phone, txt);

                        if (result.IsSuc)
                        {
                            pwd = result.Pwd;
                        }
                    }
                    else
                    {
                        // 密码登录
                        pwd    = Kit.GetMD5(txt);
                        result = await AtCm.LoginByPwd(phone, pwd);
                    }

                    if (!result.IsSuc)
                    {
                        LoginFailed(result.Error);
                        return;
                    }

                    // 保存以备自动登录
                    AtState.SaveCookie("LoginPhone", phone);
                    AtState.SaveCookie("LoginPwd", pwd);

                    Kit.InitUser(result);
                    var dlg = this.FindParentByType <Dlg>();
                    if (dlg != null)
                    {
                        // 中途登录后关闭对话框
                        dlg.Close();
                    }
                    else
                    {
                        // 正常登录后切换到主页
                        Startup.ShowHome();
                    }
                    // 接收服务器推送
                    Startup.RegisterSysPush();
                }
                catch
                {
                    LoginFailed("登录失败!");
                }
            }
        }