コード例 #1
0
        protected void btnSubmitVerification_Click(object sender, EventArgs e)
        {
            //
            //When verification is submitted, send it over to the api
            //
            string code  = txtVerificationCode.Text;
            string email = lblEmail.Text;

            VerificationCredentials cred = new VerificationCredentials();

            cred.email = email;
            cred.code  = code;
            WebRequest request = WebRequest.Create(authWebAPI + "verify");

            request.Method = "POST";
            JavaScriptSerializer json = new JavaScriptSerializer();
            string jsonCred           = json.Serialize(cred);

            byte[] postData = Encoding.ASCII.GetBytes(jsonCred);
            request.ContentType   = "application/json";
            request.ContentLength = postData.Length;

            Stream requestStream = request.GetRequestStream();

            requestStream.Write(postData, 0, postData.Length);

            WebResponse  response      = request.GetResponse();
            Stream       theDataStream = response.GetResponseStream();
            StreamReader reader        = new StreamReader(theDataStream);
            string       responseData  = reader.ReadToEnd();

            if (responseData.Length <= 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "FailureToast", "showDBError();", true);
            }
            else
            {
                //
                //If the code was correct, the API sends back their account
                //
                User foundAccount = json.Deserialize <User>(responseData);

                Session["RegisteringUserID"] = foundAccount.userID;
                Session["token"]             = foundAccount.token;

                Response.Redirect("Registration.aspx");
            }
        }
コード例 #2
0
        public User TryVerify([FromBody] VerificationCredentials cred)
        {
            //
            //User is trying to verify
            //      Works in a similar way to logging in. Returns the userid and token if the code was correct
            //

            try {
                User       registeringUser = new User();
                SqlCommand commandObj      = new SqlCommand();
                commandObj.Parameters.Clear();
                commandObj.CommandType = CommandType.StoredProcedure;
                commandObj.CommandText = "TP_CheckVerification";

                commandObj.Parameters.AddWithValue("@EmailAddress", cred.email);
                commandObj.Parameters.AddWithValue("@Verification", cred.code);
                commandObj.Parameters.Add("@UserID", SqlDbType.Int, 50).Direction = ParameterDirection.Output;

                DBConnect OBJ = new DBConnect();
                DataSet   ds  = OBJ.GetDataSetUsingCmdObj(commandObj);

                if (ds.Tables.Count == 1)
                {
                    registeringUser.userID = commandObj.Parameters["@UserID"].Value.ToString();
                    registeringUser.token  = GenerateJSONWebToken();
                    return(registeringUser);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }