Skip to content

Instantly share code, notes, and snippets.

@abhilash2006
Created February 19, 2013 11:19
Show Gist options
  • Save abhilash2006/4984987 to your computer and use it in GitHub Desktop.
Save abhilash2006/4984987 to your computer and use it in GitHub Desktop.
Google Authintication VB.NET
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports Google.GData.Client
Imports Google.GData.Contacts
Public Class GoogleAppsAuth
Private GoogleContactsService As New Google.GData.Contacts.ContactsService("mail")
Private GoogleService As Service
Private GoogleAuthToken As String
Public Function fGetConnectionString() As String
Return System.Web.Configuration.WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
End Function
Public Function fAuthenticationDatabase(ByVal UserID As String) As String
Dim _Connection As New SqlConnection(Me.fGetConnectionString)
Dim _ReturnValue As String
Dim _Command As New SqlCommand
With _Command
.CommandType = CommandType.StoredProcedure
.CommandText = "ValidateDatabaseUser"
.Connection = _Connection
.Parameters.Add(New SqlParameter("UserID", UserID))
End With
Try
If _Connection.State = ConnectionState.Closed Then _Connection.Open()
_ReturnValue = _Command.ExecuteScalar
Catch ex As Exception
Return ex.Message
Finally
_Connection.Close()
End Try
Return _ReturnValue
End Function
Public Function fAuthentication(ByVal LoginName As String, ByVal Password As String) As String()
Dim Authentication(2) As String
Try
Me.GoogleService = GoogleContactsService
Me.GoogleService.setUserCredentials(LoginName, Password)
Me.GoogleAuthToken = Me.GoogleService.QueryClientLoginToken()
If Me.GoogleAuthToken Is Nothing Then
Authentication(0) = "ERROR"
Else
Authentication(0) = "OK"
Authentication(1) = GoogleAuthToken
Authentication(2) = fAuthenticationDatabase(LoginName)
End If
Catch exLoggedException As Google.GData.Client.LoggedException
Authentication(0) = "ERROR"
Authentication(1) = exLoggedException.Message
Catch ex As Exception
Authentication(0) = "ERROR"
Authentication(1) = ex.ToString
End Try
Return Authentication
End Function
Public Function fActivateAlumniUser(ByVal UserID As String, ByVal passw As String, ByVal stunum As String, ByVal fname As String, ByVal lname As String, ByVal dob As String) As String()
Dim _Connection As New SqlConnection(Me.fGetConnectionString)
Dim _ReturnValue(2) As String
Dim _Command As New SqlCommand
Dim _Sqlurlid As New SqlParameter("@urlid", SqlDbType.VarChar, 150)
_Sqlurlid.Direction = ParameterDirection.Output
Dim _Sqlretval As New SqlParameter("@ReturnValue", SqlDbType.Int)
_Sqlretval.Direction = ParameterDirection.ReturnValue
With _Command
.CommandType = CommandType.StoredProcedure
.CommandText = "validatealumni"
.Connection = _Connection
.Parameters.Add(New SqlParameter("@username", UserID))
.Parameters.Add(New SqlParameter("@passw", passw))
.Parameters.Add(New SqlParameter("@stunum", stunum))
.Parameters.Add(New SqlParameter("@fname", fname))
.Parameters.Add(New SqlParameter("@lname", lname))
.Parameters.Add(New SqlParameter("@dob", Convert.ToDateTime(dob)))
.Parameters.Add(_Sqlurlid)
.Parameters.Add(_Sqlretval)
End With
Try
If _Connection.State = ConnectionState.Closed Then _Connection.Open()
_Command.ExecuteNonQuery()
_ReturnValue(0) = Convert.ToInt32(_Command.Parameters("@ReturnValue").Value)
_ReturnValue(1) = Convert.ToString(_Command.Parameters("@urlid").Value)
Catch ex As Exception
_ReturnValue(0) = "ERROR"
_ReturnValue(1) = ex.Message
Finally
_Connection.Close()
End Try
Return _ReturnValue
End Function
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment