forked from Vonage/vonage-dotnet-code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VerifyController.cs
109 lines (95 loc) · 3.01 KB
/
VerifyController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Nexmo.Api;
namespace NexmoDotnetCodeSnippets.Controllers
{
public class VerifyController : Controller
{
public Client Client { get; set; }
public VerifyController()
{
Client = new Client(creds: new Nexmo.Api.Request.Credentials
{
ApiKey = "NEXMO_API_KEY",
ApiSecret = "NEXMO_API_SECRET"
});
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Start(string to)
{
var RECIPIENT_NUMBER = to;
var start = Client.NumberVerify.Verify(new NumberVerify.VerifyRequest
{
number = RECIPIENT_NUMBER,
brand = "AcmeInc"
});
if (start.status == "0")
{
HttpContext.Session.SetString("RequestId", start.request_id);
ViewBag.verificationResult = $"Your PIN code was successfully sent to {RECIPIENT_NUMBER}, your request ID is {start.request_id}.";
}
else
ViewBag.verificationResult = start.error_text;
return View("Index");
}
[HttpPost]
public ActionResult Check(string code)
{
var result = Client.NumberVerify.Check(new NumberVerify.CheckRequest
{
request_id = HttpContext.Session.GetString("RequestId"),
code = code
}); ;
if (result.status == "0")
{
ViewBag.checkMessage = "Verification Sucessful";
}
else
{
ViewBag.checkMessage = result.error_text;
}
return View("Index");
}
[HttpPost]
public ActionResult Search(string requestID)
{
var search = Client.NumberVerify.Search(new NumberVerify.SearchRequest
{
request_id = requestID
});
ViewBag.error_text = search.error_text;
ViewBag.status = search.status;
return View("Index");
}
[HttpPost]
public ActionResult Cancel(string requestID)
{
var results = Client.NumberVerify.Control(new NumberVerify.ControlRequest
{
request_id = requestID,
cmd = "cancel"
});
ViewBag.cancelstatus = results.status;
return View("Index");
}
[HttpPost]
public ActionResult TriggerNext(string requestID)
{
var results = Client.NumberVerify.Control(new NumberVerify.ControlRequest
{
request_id = requestID,
cmd = "trigger_next_event"
});
ViewBag.nextMessage = results.status;
return View("Index");
}
}
}