zoukankan      html  css  js  c++  java
  • 登陆、注册、用户信息等接口文档与示例

    本来写在数据库的接口示例里面,想了想感觉不太妥当,所以新开博客。

    目录

    登陆、注册
    用户信息


    登陆、注册

    使用com.example.dell.auth.ServerAuthenticator类

    接口:

    static public boolean signIn(String username, String password, Bundle bundle):登陆。参数中username与password为用户名与密码,bundle用于返回服务器的结果;返回值表示能否与服务器通信,为true表示与服务器通信,为false表示不能与服务器通信;假如返回值为true,bundle中有属性boolean success表示是否成功登陆,String msg表示服务器返回的信息,若属性boolean success为true,bundle中还有属性String token表示token(详见Example)

    static public boolean signUp(String username, String password, Bundle bundle):注册。参数中username与password为用户名与密码,bundle用于返回服务器的结果;返回值表示能否与服务器通信,为true表示与服务器通信,为false表示不能与服务器通信;假如返回值为true,bundle中有属性boolean success表示是否成功注册,String msg表示服务器返回的信息(详见Example)。

    Example. 登陆

    前提:name passwd是已有的字符串

            Bundle bundle = new Bundle();
            boolean status = ServerAuthenticator.signIn(name, passwd, bundle);
            if(status == false) {
                    // 接口错误或者网络错误
            }
            else {
                    boolean success = bundle.getBoolean("success");
                    String msg = bundle.getString("msg");
                    // success表示操作成功与否;msg表示服务器返回信息
                    if(success) {
                            // 只有success时才有token
                            String token = bundle.getString("token");
                    }
            }
    

    Example. 注册

    前提:name passwd是已有的字符串

            Bundle bundle = new Bundle();
            boolean status = ServerAuthenticator.signUp(name, passwd, bundle);
            if(status == false) {
                    // 接口错误或者网络错误
            }
            else {
                    boolean success = bundle.getBoolean("success");
                    String msg = bundle.getString("msg");
                    // success表示操作成功与否;msg表示服务器返回信息
            }
    


    用户信息

    使用com.example.dell.auth.MyAccount类

    字段:

    • String name(用户名)
    • String token(token)
    • String nickname(昵称)
    • String gender(性别)
    • String birthday(生日)
    • String email(邮箱)
    • String school(学校)
    • String signature(个性签名)
    • int image(头像)

    接口:

    static public MyAccount get(Context context):用于获得一个MyAccount对象。由于账户有唯一性,这个类不允许直接new,只能通过这个方法获得唯一的一个对象。即,不管在什么地方,调用这个函数获得的都是同一个对象。

    getter and setter:上面那些字段的getter和setter。详略。

    save:为了减少文件操作,如果修改了字段,只有调用这个函数才会保存当前的所有属性,否则不会保存。

    Example. 获取用户信息

            MyAccount myAccount = MyAccount.get(getContext());
            String name = myAccount.getName();    // 类似可以调用其他getter方法获取其他属性
    

    Example. 编辑用户信息

            MyAccount myAccount = MyAccount.get(getContext());
            myAccount.setName("hello");
            myAccount.setSchool("USTC");
            myAccount.save();    // 假如不save,这些信息不会保存,即本次还是能够得到设置的值,但下次打开app时不会得到设置的值
    
  • 相关阅读:
    旋转数组的最小数字
    二维数组中的查找问题--剑指offer面试题3
    百度软件开发实习生c++方向面经(一面)
    一些常考的智力题
    灵感闪现 篇 (一) 2d场景 3d 效果
    GameUnity 2.0 文档(四) 网格+四叉树 最优碰撞检测
    GameUnity 2.0 文档(三) 纸片人八方向
    GameUnity 2.0 文档(二) 纸片人系统
    GameUnity 2.0 文档(一) 事件机制
    GameUnity 2.0 发布倒计时
  • 原文地址:https://www.cnblogs.com/USTC-CC/p/9313211.html
Copyright © 2011-2022 走看看