private async void btnRegisterClick(object sender, EventArgs e)
        {
            if (checkValidateData() == true)
            {
                await Utilities_API.API_GetRegister(_edtID.Text, _edtEmail.Text, _edtPassword.Text);

                BeanNguoiDung result = Utilities_API.RESULT_APIREGISTER_BEANNGUOIDUNG;
                if (result != null) // dang ky thanh cong
                {
                    if (!String.IsNullOrEmpty(result.MaNguoiDung) && !String.IsNullOrEmpty(result.TaiKhoan) && !String.IsNullOrEmpty(result.MatKhau) &&
                        result.KichHoat == false)    // thanh cong - chua kich hoat
                    {
                        Toast.MakeText(this, "Đăng ký thành công!", ToastLength.Long).Show();
                        Finish();
                        Intent intent = new Intent(this, typeof(Activity_Login_ConfirmOTP));
                        intent.PutExtra("Email", result.Email);
                        intent.PutExtra("MaNguoiDung", result.MaNguoiDung);
                        intent.PutExtra("TaiKhoan", result.TaiKhoan);
                        intent.PutExtra("MatKhau", result.MatKhau);
                        StartActivity(intent);
                    }
                    else
                    {
                        Toast.MakeText(this, "Đăng ký thất bại!", ToastLength.Long).Show();
                    }
                }
            }
        }
        public static async Task <BeanNguoiDung> API_Test(string email, string password)
        {
            BeanNguoiDung _resultNguoiDung = null;

            try
            {
                _APIDetailName     = "/Link/ApiMon.ashx?func=select";
                _BeanAPIResult     = new BeanAPI();
                client             = new HttpClient();
                client.BaseAddress = new Uri(_SiteName);

                var jsonData = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("Data", "{MaMon:2,}")
                });

                //HttpContent content = new StringContent(jsonData, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PostAsync(_APIDetailName, jsonData);

                if (response.IsSuccessStatusCode) // thanh cong -> lay ket qua ve
                {
                    _BeanAPIResult = JsonConvert.DeserializeObject <BeanAPI>(await response.Content.ReadAsStringAsync());
                    if (!String.IsNullOrEmpty(_BeanAPIResult.data))
                    {
                        _resultNguoiDung = new BeanNguoiDung();
                        _resultNguoiDung = JsonConvert.DeserializeObject <BeanNguoiDung>(_BeanAPIResult.data);
                    }
                }
                return(_resultNguoiDung);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        /// <summary>
        /// Neu thanh cong -> true, that bai -> false
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static async Task API_UpdateUser(BeanNguoiDung user)
        {
            try
            {
                _APIDetailName     = "/api/values";
                _BeanAPIResult     = new BeanAPI();
                client             = new HttpClient();
                client.BaseAddress = new Uri(_SiteName);

                var jsonData = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("Data", "{" + JsonConvert.SerializeObject(user) + "}")
                });

                HttpResponseMessage response = await client.PostAsync(_APIDetailName, jsonData);

                if (response.IsSuccessStatusCode) // thanh cong -> lay ket qua ve
                {
                    _BeanAPIResult = JsonConvert.DeserializeObject <BeanAPI>(await response.Content.ReadAsStringAsync());
                    if (_BeanAPIResult.status.Equals("SUCCESS"))
                    {
                        //_result = true;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        /// <summary>
        /// Neu thanh cong -> OK, that bai -> NO
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static async Task API_ConfirmOTP(string MaNguoiDung, string OTP)
        {
            //http://localhost:63211/Link/ApiNguoiDung.ashx?func=authentication&data={MaNguoiDung:1,MaOTP:1}
            try
            {
                RESULT_APIOTP_BOOL = false;
                _APIDetailName     = "/Link/ApiNguoiDung.ashx?func=authentication";
                _BeanAPIResult     = new BeanAPI();
                client             = new HttpClient();
                client.BaseAddress = new Uri(_SiteName);

                var jsonData = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("Data", "{MaNguoiDung:\"" + MaNguoiDung + "\", MaOTP:\"" + OTP + "\"}")
                });

                HttpResponseMessage response = await client.PostAsync(_APIDetailName, jsonData);

                if (response.IsSuccessStatusCode) // thanh cong -> lay ket qua ve
                {
                    _BeanAPIResult = JsonConvert.DeserializeObject <BeanAPI>(await response.Content.ReadAsStringAsync());
                    if (_BeanAPIResult.status.Equals("SUCCESS"))
                    {
                        RESULT_APIOTP_BOOL = true;
                        RESULT_APICONFIRMOTP_BEANNGUOIDUNG = JsonConvert.DeserializeObject <BeanNguoiDung>(_BeanAPIResult.data);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        /// <summary>
        /// Neu thanh cong -> BeanNguoiDung, that bai -> null
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static async Task API_GetLogIn(string id, string password)
        {
            try
            {
                //http://localhost:63211/Link/ApiNguoiDung.ashx?func=signin&data={TaiKhoan:%22user1%22,MatKhau:%22123456%22}
                _APIDetailName     = "/Link/ApiNguoiDung.ashx?func=signin";
                _BeanAPIResult     = new BeanAPI();
                client             = new HttpClient();
                client.BaseAddress = new Uri(_SiteName);

                var jsonData = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("Data", "{TaiKhoan:\"" + id + "\", MatKhau:\"" + password + "\"}")
                });
                HttpResponseMessage response = await client.PostAsync(_APIDetailName, jsonData);

                if (response.IsSuccessStatusCode) // thanh cong -> lay ket qua ve
                {
                    _BeanAPIResult = JsonConvert.DeserializeObject <BeanAPI>(await response.Content.ReadAsStringAsync());
                    if (_BeanAPIResult.status.Equals("SUCCESS"))
                    {
                        if (!String.IsNullOrEmpty(_BeanAPIResult.data))
                        {
                            RESULT_APILOGIN_BEANNGUOIDUNG = JsonConvert.DeserializeObject <BeanNguoiDung>(_BeanAPIResult.data);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #6
0
        private async void Click_Login(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(_edtEmail.Text) || String.IsNullOrEmpty(_edtPassword.Text))
            {
                Toast.MakeText(this, "Vui lòng nhập đủ thông tin!", ToastLength.Long).Show();
            }
            else // nhap du thong tin
            {
                //Intent intent = new Intent(this, typeof(Activity_Login_ConfirmOTP));
                //StartActivity(intent);

                await Utilities_API.API_GetLogIn(_edtEmail.Text, _edtPassword.Text);

                BeanNguoiDung result = Utilities_API.RESULT_APILOGIN_BEANNGUOIDUNG;
                if (result != null)
                {
                    if (!String.IsNullOrEmpty(result.MaNguoiDung) && !String.IsNullOrEmpty(result.TaiKhoan) &&
                        !String.IsNullOrEmpty(result.MatKhau)) // thanh cong
                    {
                        // kiem tra coi co confirm otp chua
                        if (result.KichHoat == true) // da kich hoat
                        {
                            BeanSession session = new BeanSession(result.MaNguoiDung, result.TaiKhoan, result.MatKhau, result.HoTen, result.GioiTinh,
                                                                  result.NgaySinh, result.HinhAnh, result.Email, result.LoaiNguoiDung, result.KhoaNguoiDung, result.MaOtp, result.KichHoat,
                                                                  result.Created, result.Modified, result.CreatedBy, result.ModifiedBy);
                            SQLiteDataHandler.BeanSession_AddSession(session);
                            Finish();
                            Intent intent = new Intent(this, typeof(Activity_Home));
                            StartActivity(intent);
                        }
                        else // chua kich hoat
                        {
                            Finish();
                            Intent intent = new Intent(this, typeof(Activity_Login_ConfirmOTP));
                            intent.PutExtra("MaNguoiDung", result.MaNguoiDung);
                            intent.PutExtra("TaiKhoan", result.TaiKhoan);
                            intent.PutExtra("MatKhau", result.MatKhau);
                            StartActivity(intent);
                        }
                    }
                    else
                    {
                        Toast.MakeText(this, "Đăng nhập thất bại!", ToastLength.Long).Show();
                    }
                }
            }
        }
        /// <summary>
        /// Neu thanh cong -> MaNguoiDung, that bai -> null
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static async Task API_GetRegister(string TaiKhoan, string Email, string password)
        {
            try
            {
                RESULT_APIREGISTER_BEANNGUOIDUNG = new BeanNguoiDung();
                //http://c3da38bf.ngrok.io/Link/ApiNguoiDung.ashx?func=signup&data={TaiKhoan:khoatest,Email:[email protected],MatKhau:Aa123456}
                _APIDetailName     = "/Link/ApiNguoiDung.ashx?func=signup";
                _BeanAPIResult     = new BeanAPI();
                client             = new HttpClient();
                client.BaseAddress = new Uri(_SiteName);

                var jsonData = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("Data", "{TaiKhoan:\"" + TaiKhoan + "\"," +
                                                      "MatKhau:\"" + password + "\"," +
                                                      "Email:\"" + Email + "\"}"
                                                      )
                });
                HttpResponseMessage response = await client.PostAsync(_APIDetailName, jsonData);

                if (response.IsSuccessStatusCode) // thanh cong -> lay ket qua ve
                {
                    _BeanAPIResult = JsonConvert.DeserializeObject <BeanAPI>(await response.Content.ReadAsStringAsync());
                    if (_BeanAPIResult.status.Equals("SUCCESS"))
                    {
                        if (!String.IsNullOrEmpty(_BeanAPIResult.data))
                        {
                            List <BeanNguoiDung> temp = JsonConvert.DeserializeObject <List <BeanNguoiDung> >(_BeanAPIResult.data);
                            if (temp.Count > 0)
                            {
                                RESULT_APIREGISTER_BEANNGUOIDUNG = temp[0];
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #8
0
        private async void SendOTP(object sender, EventArgs e)
        {
            if (_edtOTP.Text.Length == 6)
            {
                if (!String.IsNullOrEmpty(_MaNguoiDung))
                {
                    // get List Mon An
                    await Utilities_API.API_ConfirmOTP(_MaNguoiDung, _edtOTP.Text);

                    bool          result_confirm = Utilities_API.RESULT_APIOTP_BOOL;
                    BeanNguoiDung result         = Utilities_API.RESULT_APICONFIRMOTP_BEANNGUOIDUNG;
                    if (result_confirm == true)
                    {
                        Toast.MakeText(this, "Xác nhận OTP thành công!", ToastLength.Long).Show();
                        // Add session
                        BeanSession session = new BeanSession(result.MaNguoiDung, result.TaiKhoan, result.MatKhau, result.HoTen, result.GioiTinh,
                                                              result.NgaySinh, result.HinhAnh, result.Email, result.LoaiNguoiDung, result.KhoaNguoiDung, result.MaOtp, result.KichHoat,
                                                              result.Created, result.Modified, result.CreatedBy, result.ModifiedBy);
                        SQLiteDataHandler.BeanSession_AddSession(session);
                        Finish();
                        Intent intent = new Intent(this, typeof(Activity_Home));
                        StartActivity(intent);
                    }
                    else if (result_confirm == false)
                    {
                        Toast.MakeText(this, "Xác nhận OTP thất bại!", ToastLength.Long).Show();
                    }
                }
                else
                {
                    Toast.MakeText(this, "Tài khoản có lỗi xảy ra", ToastLength.Long).Show();
                }
            }
            else
            {
                Toast.MakeText(this, "Mã OTP không hợp lệ", ToastLength.Long).Show();
            }
        }