智能管家App kotlin版(3)——用户注册/登录/忘记重置密码/个人数据编辑开发

本文详述了利用Bmob后端云平台搭建用户系统的全过程,包括用户注册、登录、找回密码、修改密码、邮箱验证及个人信息编辑等功能。通过Kotlin语言实现了UI界面设计与逻辑交互,介绍了如何集成Bmob进行用户数据管理和验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言:Bmob后端云为我们用户操作带来了极大的便捷,本文章主要是涵盖了一个用户系统逻辑,实现用户的登录,注册,找回密码,修改密码,邮箱验证,以及记住密码等功能的实现,通过本章你可以学习到宝贵的用户操作逻辑,同时可以学习到自定义的Dialog以及头像的选择和裁剪!

此篇文章紧做关于该项目的用户注册/登录/忘记重置密码开发,后续功能实现请关注后续文章!!!

此文章实现功能将过程中,分布展示!!!

一.用户管理—Bmob简单集成

这地方我并没有什么自己的见解,只是按照官方文档,一步步操作罢了

官方文档

二.用户管理—用户注册功能开发

功能截图:
在这里插入图片描述
1.在ui包下,创建RegisteredActivity,编写注册界面交互界面:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp"
    tools:context=".ui.RegisteredActivity">

    <EditText
        android:id="@+id/et_user"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/text_user_name"/>

    <EditText
        android:id="@+id/et_age"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/text_age"/>

    <EditText
        android:id="@+id/et_desc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/text_desc"
        android:lines="2"/>

    <RadioGroup
        android:id="@+id/mRadioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/rb_boy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/text_boy"/>

        <RadioButton
            android:id="@+id/rb_girl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="@string/text_girl_f"/>

    </RadioGroup>


    <EditText
        android:id="@+id/et_pass"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/text_password"
        android:inputType="textPassword"/>

    <EditText
        android:id="@+id/et_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/text_password_again"
        android:inputType="textPassword"
        />

    <EditText
        android:id="@+id/et_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/text_email"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/text_register_remind"
        android:textColor="@color/colorAccent"
        android:textSize="15sp"/>


    <Button
        android:id="@+id/btnRegistered"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@drawable/button_bg"
        android:text="@string/text_registered"
        android:textColor="@android:color/white"/>

</LinearLayout>

2.编写kotlin交互代码,代码如下:

package com.zrc.smartbutler.ui

import android.os.Bundle
import android.text.TextUtils
import android.widget.Toast
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.SaveListener
import com.zrc.smartbutler.R
import com.zrc.smartbutler.entity.MyUser
import com.zrc.smartbutler.utils.L
import kotlinx.android.synthetic.main.activity_registered.*


/**
 *
 *  项目名:  SmartButler
 *  包名:    com.zrc.smartbutler.ui
 *  文件名:   RegisteredActivity
 *  创建者:   张如成
 *  创建时间:  2020/5/7 22:11
 *  描述:    注册
 */
class RegisteredActivity : BaseActivty() {
   

    //性别
    private var isGender = true
    override fun onCreate(savedInstanceState: Bundle?) {
   
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_registered)
        //返回键
        back()

        initView();
    }

    private fun initView() {
   
        //注册按钮点击事件
        btnRegistered.setOnClickListener {
   
            //获取到输入框的值
            val name = et_user.text.trim()
            val age = et_age.text.trim()
            var desc = et_desc.text.trim()
            val pass = et_pass.text.trim()
            val password = et_password.text.trim()
            val email = et_email.text.trim()

            //判断是否为空
            if (!TextUtils.isEmpty(name) and !TextUtils.isEmpty(age) and
                    !TextUtils.isEmpty(pass) and
                    !TextUtils.isEmpty(password) and
                    !TextUtils.isEmpty(email)) {
   
                //判断两次密码是否一致
                if(pass.equals(password)){
   
                    //性别判断
                    mRadioGroup.setOnCheckedChangeListener {
    group, checkedId ->
                        if (checkedId == R.id.rb_boy) {
   
                            isGender = true
                        } else if (checkedId == R.id.rb_girl) {
   
                            isGender = false
                        }
                    }
                    //判断简介是否为空
                    if(TextUtils.isEmpty(desc)){
   
                        desc = "这个人很懒,什么都没有留下"
                    }

                    L().i("desc.toString() = "+ desc.toString())
                    L().i("age.toString() = "+ age.toString())
                    //注册
                    val user = MyUser()
                    user.setAge(age.toString().toInt())
                    user.setDesc(desc.toString())
                    user.setSex(isGender)
                    user.username = name.toString()
                    user.setPassword(password.toString())
                    user.email = email.toString()

                    user.signUp(object : SaveListener<MyUser>() {
   
                        override fun done(user: MyUser, e: BmobException) {
   
                            if (e == null) {
   
                                Toast.makeText(RegisteredActivity(),"注册成功",Toast
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值