public SignupResponse Signup(int ClinicId, string PatientId, string AppointmentId, string Phone, string EMail, string VisitStart) { try { string resp = POST("signup", new[] { new POSTData("csrfmiddlewaretoken", "NOTPROVIDED"), new POSTData("appointment_form-clinic_id", ClinicId.ToString()), new POSTData("appointment_form-history_id", ""), new POSTData("appointment_form-patient_id", PatientId), new POSTData("appointment_form-appointment_id", AppointmentId), new POSTData("appointment_form-phone", Phone), new POSTData("appointment_form-email", EMail), new POSTData("appointment_form-visit_start", VisitStart), new POSTData("appointment_form-referal_id", "") }); SignupResponseTemp t = JsonConvert.DeserializeObject <SignupResponseTemp>(resp); SignupResponse r = new SignupResponse() { error = t.error, success = t.success, response = resp }; return(r); } catch { return(new SignupResponse() { success = false }); } }
public async Task <IActionResult> SinginAsync(SignupRequest request) { try { var response = new SignupResponse(); var user = userService.FindUser(request.Name, request.LastName, request.Email); if (user != null) { response.Code = 202; response.Message = "User already exist."; return(Ok(response)); } user = new User { Name = request.Name, LastName = request.LastName, Email = request.Email }; await userService.Save(user); response.Success = true; response.Message = "The user has successfully registered."; response.Code = 200; return(Ok(response)); } catch (Exception ex) { _logger.LogError("An error has occurred on " + ex); throw; } }
void SendResultInfoAsJson(SignupResponse res) { string strJson = JsonConvert.SerializeObject(res); Response.ContentType = "application/json; charset=utf-8"; Response.Write(strJson); Response.End(); }
public void NegativeTest() { SignupRequest BodyWithoutPhone = new SignupRequest { first_name = "Иван", last_name = "Иванов", birthday = "31.10.1991", phone = "", password = "******", test_mode = "1", sex = "2" }; SignupResponse res = Api.Signup(BodyWithoutPhone).Data; Assert.AreEqual(100, res.Error.ErrorCode, "Error code is 100"); Assert.AreEqual("One of the parameters specified was missing or invalid: phone is undefined", res.Error.ErrorMsg); }
public void PositiveTest() { SignupRequest BodyWithAllData = new SignupRequest { first_name = "Иван", last_name = "Иванов", birthday = "31.10.1991", phone = "+79110885340", password = "******", test_mode = "1", sex = "2" }; IRestResponse <SignupResponse> res = Api.Signup(BodyWithAllData); SignupResponse resData = res.Data; Assert.AreEqual(HttpStatusCode.OK, res.StatusCode, "Http status is 200 OK"); // probably raw response might be useful in such cases Assert.IsNotEmpty(resData.Response.Sid, "There is sid"); }
async Task Signup() { SignupResponse signupResponse = await _dbHelper.SignUp(new SignupRequest { Username = SignupRequest.Username, Password = SignupRequest.Password, FirstName = SignupRequest.FirstName, LastName = SignupRequest.LastName, Address = SignupRequest.Address, Email = SignupRequest.Email }); if (!signupResponse.Success) { await _dialogService.ShowMessage("Unable to sign user", "Error", "OK", null); } else { await _navigation.PopToRootAsync(); } }
public async Task <SignupResponse> SignUp(SignupRequest request) { SignupResponse signupResponse = new SignupResponse(); try { signupResponse = await App.Database.SignUp(new SignupRequest { Username = request.Username, Password = request.Password, FirstName = request.FirstName, LastName = request.LastName, Address = request.Address, Email = request.Email }); } catch (Exception e) { await _dialogService.ShowMessage($"The server returned an error: {e.Message}", "Error", "OK", null); } return(signupResponse); }
protected void Page_Load(object sender, EventArgs e) { SignupRequest req; SignupResponse res = new SignupResponse(); res.error = String.Empty; // 1. Deserialize the incoming Json. try { req = GetRequestInfo(); } catch (Exception ex) { res.error = ex.Message.ToString(); // Return the results as Json. SendResultInfoAsJson(res); return; } SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); try { connection.Open(); string getUserInfo = String.Format("select UserID,FirstName,LastName from ContactUser.Users where UserName='******' and Password='******'", req.login, req.password); SqlCommand command = new SqlCommand(getUserInfo, connection); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { res.error = "User Name already created"; SendResultInfoAsJson(res); return; } reader.Close(); string sql = String.Format("INSERT INTO ContactUser.Users (FirstName, LastName, Email, UserName, Password) Values('{0}', '{1}', '{2}', '{3}', '{4}')", req.firstName, req.lastName, req.email, req.login, req.password); command = new SqlCommand(sql, connection); command.ExecuteNonQuery(); command = new SqlCommand(getUserInfo, connection); reader = command.ExecuteReader(); if (reader.HasRows) { if (reader.Read()) { res.id = Convert.ToInt32(reader["UserID"]); res.firstName = Convert.ToString(reader["FirstName"]); res.lastName = Convert.ToString(reader["LastName"]); } } reader.Close(); } catch (Exception ex) { res.error = ex.Message.ToString(); } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } // Return the results as Json. SendResultInfoAsJson(res); }
//public ArrayList getSignup(Signup signup) public SignupResponse GetSignup(Signup signup) { OleDbConnection conn = null; OleDbCommand command = null; OleDbDataReader mySQLReader = null; var hash = System.Security.Cryptography.SHA512.Create(); SignupResponse signupResponse = new SignupResponse(); signupResponse.Message = "Not Found"; signupResponse.Status = "Fail"; bool hasRows = false; bool hasRowsOTP = false; try { string myConnectionString = ConfigurationManager.ConnectionStrings["localDB"].ConnectionString;; conn = new OleDbConnection(myConnectionString); conn.Open(); command = new OleDbCommand(); command.Connection = conn; command.CommandTimeout = 0; //-------------Return command.CommandType = CommandType.Text; //command.CommandText = "select CONVERT(nvarchar(max),ID_Card,2) as ID_Card , Mobile_No, Pin from SrvA_PIN where Flag = 1"; if (signup.Type.Equals("1")) { command.CommandText = "select UnitHolder, ID_Card from SrvA_Customer_Cloud where UnitHolder = ? and ID_Card = ? and Mobile_No = ? and Flag = 1"; command.Parameters.Clear(); command.Parameters.AddWithValue("@UnitHolder", signup.UnitHolder == null ? "" : signup.UnitHolder.Trim()); command.Parameters.AddWithValue("@ID_Card", signup.ID_Card == null ? new byte[0] : hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(signup.ID_Card.Trim()))); command.Parameters.AddWithValue("@Mobile_No", signup.Mobile_No == null ? new byte[0] : hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(signup.Mobile_No.Trim()))); } else { command.CommandText = "select UnitHolder, ID_Card from SrvA_Customer_Cloud where Username = ? and Password = ? and Mobile_No = ? and Flag = 1"; command.Parameters.Clear(); command.Parameters.AddWithValue("@Username", signup.Username == null ? "" : signup.Username.Trim()); command.Parameters.AddWithValue("@Password", signup.Password == null ? "" : signup.Password.Trim()); command.Parameters.AddWithValue("@Mobile_No", hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(signup.Mobile_No.Trim()))); } mySQLReader = command.ExecuteReader(); while (mySQLReader.Read()) { //mySQLReader.GetString(mySQLReader.GetOrdinal("UnitHolder")); signupResponse.Message = "Waiting for OTP"; signupResponse.Status = "OK"; } if (mySQLReader.HasRows) { hasRows = true; } mySQLReader.Close(); if (hasRows) { char[] separators = new char[] { ' ', ';', ',', '\r', '\t', '\n', '-' }; string mobile = ""; string[] temp = signup.Mobile_No.Split(separators, StringSplitOptions.RemoveEmptyEntries); mobile = String.Join("\n", temp); mobile = "+66" + mobile.Substring(1, mobile.Length - 1); signupResponse.Status = mobile; //-------------------------------- OTP Generate -------------------------- string OTP = ""; byte[] secretkey = new Byte[64]; using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) { // The array is now filled with cryptographically strong random bytes. rng.GetBytes(secretkey); // Use the secret key to sign the message file. //SignFile(secretkey, dataFile, signedFile); // Verify the signed file //VerifyFile(secretkey, signedFile); } OtpAuthenticator otpAuthenticator = new OtpAuthenticator(0, OtpAlgorithm.SHA512, secretkey); OTP = otpAuthenticator.GetOtp(); signupResponse.Status = OTP; //-------------------------------- /OTP Generate -------------------------- //signupResponse.Status = Helper.base64Decode("aT4Zr2ziKVZf4a+hGvyZfWHgYcU="); //signupResponse.Status = Helper.base64Encode("bblam"); //signupResponse.Status = Convert.ToBase64String(Base32.Decode("g+6JjGHD75cSeRBQOvkyXQ")); //signupResponse.Status = Helper.EncodePassword("bblam", "123456"); //MembershipProvider membershipProvider = new MembershipProvider(); //signupResponse.Status = FormsAuthentication.HashPasswordForStoringInConfigFile("CHULAT3pit6T+AnxAEWFslVd5Lw==","sha1"); //CryptoStream c = new CryptoStream(); byte[] bytes = System.Text.Encoding.Unicode.GetBytes("Password7"); //password byte[] src = Convert.FromBase64String("g+6JjGHD75cSeRBQOvkyXQ=="); //salt //byte[] src = System.Text.Encoding.UTF8.GetBytes("g+6JjGHD75cSeRBQOvkyXQ==");//salt byte[] dst = new byte[src.Length + bytes.Length]; Buffer.BlockCopy(src, 0, dst, 0, src.Length); Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length); HashAlgorithm algorithm = HashAlgorithm.Create("SHA1"); byte[] inArray = algorithm.ComputeHash(dst); signupResponse.Status = Convert.ToBase64String(inArray); //var sha1 = System.Security.Cryptography.SHA1.Create(); //signupResponse.Status = Convert.ToBase64String(sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes("g+6JjGHD75cSeRBQOvkyXQ=="))); //Crypto.HashPassword(password) //-------------------------------- Ref. Generate -------------------------- Random rand = new Random(); int size = 6; //const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; char[] chars = new char[size]; for (int i = 0; i < size; i++) { chars[i] = Alphabet[rand.Next(Alphabet.Length)]; } var refNo = new string(chars); //-------------------------------- /Ref. Generate -------------------------- //-------------------------------- Check before sent OTP ---------------- // อย่าลืมผูกเงื่อนไขเพื่อตรวจสอบจากตาราง SrvA_PIN_Cloud เพื่อตรวจคนที่เคยลงทะเบียนแล้ว command.CommandType = CommandType.Text; //command.CommandText = "select * from SrvA_OTP_Cloud where (Mobile_No = ? and DATEDIFF(minute, Dt_Gen, GETDATE()) <= 3 and flag = 1) or (select count(OTP_No) from SrvA_OTP_Cloud where Mobile_No = ? and DATEDIFF(day, Dt_Gen, GETDATE()) = 0) > 3"; command.CommandText = "select * from SrvA_OTP_Cloud where (Mobile_No = ? and DATEDIFF(minute, Dt_Gen, GETDATE()) <= 10 and flag = 1) or (select count(OTP_No) from SrvA_OTP_Cloud where Mobile_No = ? and DATEDIFF(day, Dt_Gen, GETDATE()) = 0) > 3"; command.Parameters.Clear(); command.Parameters.AddWithValue("@Mobile_No", hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(signup.Mobile_No.Trim()))); command.Parameters.AddWithValue("@Mobile_No", hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(signup.Mobile_No.Trim()))); mySQLReader = command.ExecuteReader(); if (mySQLReader.HasRows) { hasRowsOTP = true; } mySQLReader.Close(); if (hasRowsOTP) { //-------------------------------- Insert OTP to Database ---------------- command.CommandType = CommandType.Text; command.CommandText = "insert into SrvA_OTP_Cloud(Mobile_No,OTP_No,Ref_No,Dt_Gen,Flag) values(?,?,?,GETDATE(),1)"; command.Parameters.Clear(); command.Parameters.AddWithValue("@Mobile_No", hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(signup.Mobile_No.Trim()))); command.Parameters.AddWithValue("@OTP_No", OTP); command.Parameters.AddWithValue("@Ref_No", refNo); command.ExecuteNonQuery(); //-------------------------------- /Insert OTP to Database ---------------- //-------------------------------- twilio -------------------------- // Find your Account Sid and Token at twilio.com/console const string accountSid = "AC15698d45616d4e4a93f1dea51c1818f3"; const string authToken = "f7a0c28c34ede98e3879381065a24f45"; TwilioClient.Init(accountSid, authToken); var message = MessageResource.Create( //body: "OTP = " + OTP, body: "OTP ของท่านคือ " + OTP + " (หมายเลขอ้างอิง " + refNo + ") OTP นี้หมดอายุใน 3 นาที", from: new Twilio.Types.PhoneNumber("+13343199559"), to: new Twilio.Types.PhoneNumber(mobile) ); Console.WriteLine(message.Sid); //-------------------------------- /twilio -------------------------- //} /* * // Find your Account Sid and Token at twilio.com/console * const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; * const string authToken = "your_auth_token"; * * TwilioClient.Init(accountSid, authToken); * * var message = MessageResource.Create( * body: "This is the ship that made the Kessel Run in fourteen parsecs?", * from: new Twilio.Types.PhoneNumber("+15017122661"), * to: new Twilio.Types.PhoneNumber("+15558675310") * ); * * Console.WriteLine(message.Sid); */ //return SignupArrayList; //return signupResponse; } //------- /hasRowsOTP else { signupResponse.Message = "Limited of OTP or old OTP still active"; signupResponse.Status = "Fail"; } //------- /hasRowsOTP else //-------------------------------- /Check before sent OTP ---------------- } else { signupResponse.Message = "Username or Mobile No. not correct"; signupResponse.Status = "Fail"; } //return forgotArrayList; return(signupResponse); } /*catch (SqlException ex) * { * throw ex; * } */ catch (Exception ex) { signupResponse.Message = ex.ToString(); signupResponse.Status = "Fail"; return(signupResponse); } finally { if (mySQLReader != null) { mySQLReader.Close(); } if (conn != null) { conn.Close(); } } }
private async void Signupbtn_Click(object sender, EventArgs e) { string nametext, mobiletext, emailtext, passtext, cnfpasstext; InputMethodManager inputManager = (InputMethodManager)GetSystemService(InputMethodService); inputManager.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0); nametext = name.Text; mobiletext = mobile.Text; emailtext = email.Text; passtext = password.Text; cnfpasstext = conpass.Text; if (!checkEmpty(nametext, "Name")) { return; } else if (!checkEmpty(mobiletext, "Phone number")) { return; } else if (!checkEmpty(emailtext, "Email")) { return; } else if (!checkEmpty(passtext, "Password")) { return; } else if (!checkEmpty(cnfpasstext, "Confirm Password")) { return; } else { if (isNameVaid(nametext) && isMobileValid(mobiletext) && isEmailValid(emailtext) && areTermsAccepted() && isPassValid(passtext) && checkPassValidity(passtext, cnfpasstext)) { mLoadingDialog.Show(); CabsAPI api = new CabsAPI(); SignupResponse response = await api.RegisterUser(nametext, emailtext, mobiletext, passtext); if (response.Code == Utils.ResponseCode.SUCCESS) { mLoadingDialog.Dismiss(); mEditor.PutString("email", emailtext); mEditor.PutString("mobile", mobiletext); mEditor.PutString("name", nametext); mEditor.PutString("token", response.Token); mEditor.PutBoolean("isLoggedIn", true); mEditor.Apply(); mTextToSpeech = new TextToSpeech(this, this, "com.google.android.tts"); // new TextToSpeech(con, this, "com.google.android.tts"); lang = Java.Util.Locale.Default; //setting language , pitch and speed rate to the voice mTextToSpeech.SetLanguage(lang); mTextToSpeech.SetPitch(1f); mTextToSpeech.SetSpeechRate(1f); mContext = signupbtn.Context; mTextToSpeech.Speak(mSucLog, QueueMode.Flush, null, null); StartActivity(new Intent(this, typeof(NavigationActivity))); Finish(); } else if (response.Code == Utils.ResponseCode.MYSQL_DUPLICATES) { mLoadingDialog.Dismiss(); Toast.MakeText(this, "User with same number is already present", ToastLength.Short).Show(); mobile.Text = ""; } else { mLoadingDialog.Dismiss(); Toast.MakeText(this, "Server Error Try Again!", ToastLength.Short).Show(); } } } }
private async void Signup_Click(object sender, RoutedEventArgs e) { //Validation of entries in the fields if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { string nametext, mobiletext, emailtext, passtext, cnfpasstext; nametext = UsernameBox.Text; mobiletext = ContactNumberBox.Text; emailtext = EmailidBox.Text; passtext = PasswordBox.Password; cnfpasstext = ConfirmPasswordBox.Password; if (!checkEmpty(nametext, "Name")) { await new MessageDialog("Name field cannot be empty").ShowAsync(); return; } else if (!checkEmpty(mobiletext, "Phone number")) { await new MessageDialog("Phone field cannot be empty").ShowAsync(); return; } else if (!checkEmpty(emailtext, "Email")) { await new MessageDialog("Email field cannot be empty").ShowAsync(); return; } else if (!checkEmpty(passtext, "Password")) { await new MessageDialog("Password field cannot be empty").ShowAsync(); return; } else if (!checkEmpty(cnfpasstext, "Confirm Password")) { await new MessageDialog("Confirm Password field cannot be empty").ShowAsync(); return; } else { if (!isNameVaid(nametext)) { await new MessageDialog("Please enter a valid Name").ShowAsync(); return; } else if (!isPassValid(passtext)) { await new MessageDialog("Password must contain at least 6 characters").ShowAsync(); return; } else if (!isEmailValid(emailtext)) { await new MessageDialog("Please enter a valid email").ShowAsync(); return; } else if (!isMobileValid(mobiletext)) { await new MessageDialog("Please enter a valid 10 digit mobile number").ShowAsync(); return; } else if (!checkPassValidity(passtext, cnfpasstext)) { await new MessageDialog("Passwords do not match").ShowAsync(); return; } else if (!areTermsAccepted()) { await new MessageDialog("You have to accept our T&C").ShowAsync(); return; } else { progress.IsActive = true; CabsAPI api = new CabsAPI(); SignupResponse response = await api.RegisterUser(UsernameBox.Text, EmailidBox.Text, ContactNumberBox.Text, PasswordBox.Password); if (response.Code == ResponseCode.SUCCESS) { progress.IsActive = false; var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; localSettings.Values["LoggedIn"] = true; localSettings.Values["Token"] = response.Token; localSettings.Values["Email"] = EmailidBox.Text; localSettings.Values["Mobile"] = ContactNumberBox.Text; localSettings.Values["Name"] = UsernameBox.Text; Frame.Navigate(typeof(Navigation.NavigationPage), speechRecognition); } else if (response.Code == ResponseCode.MYSQL_DUPLICATES) { progress.IsActive = false; await new MessageDialog("Email or Contact Number already exists. Please try again").ShowAsync(); } } } } }