def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Activating the user.') req_response = req.get_json() if req_response: id1 = req_response.get('id') LastModifierUserId = req_response.get('modifierUserId') LastModificationTime = dt.strftime('%Y-%m-%d %H:%M:%S') conn = connection.getconnection() if conn: cursor = conn.cursor() query = f"UPDATE [dbo].[Users] SET isActive='1', LastModificationTime='{LastModificationTime}' ,LastModifierUserId='{LastModifierUserId}' WHERE id='{id1}'" try: cursor.execute(query) cursor.execute("select @@rowcount") rowcount = cursor.fetchall()[0][0] if rowcount > 0: cursor.commit() conn.close() return func.HttpResponse("response", status_code=200) except Exception as ex: conn.rollback() conn.close() logging.exception( f"Exception occurred while activating - {ex}") return func.HttpResponse("Something Went Wrong!", status_code=500) else: return func.HttpResponse("No Parameters Passed", status_code=500)
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') req_response = req.get_json() if req_response: Id1 = req_response.get('id') Username = req_response.get('username') Surname = req_response.get('surname') EmailAddress = req_response.get('emailAddress') IsActive = req_response.get('isActive') Name = req_response.get('name') LastModifierUserId = req_response.get('modifierUserId') LastModificationTime = dt.strftime('%Y-%m-%d %H:%M:%S') conn = connection.getconnection() if conn: crsr = conn.cursor() query = f"UPDATE [dbo].[Users] SET UserName='******',Surname='{Surname}',EmailAddress='{EmailAddress}', IsActive='{IsActive}',Name='{Name}',LastModificationTime='{LastModificationTime}',LastModifierUserId='{LastModifierUserId}' WHERE id='{Id1}'" try: crsr.execute(query) crsr.execute("select @@rowcount") rowcount = crsr.fetchall()[0][0] crsr.commit() conn.close() if rowcount > 0: return func.HttpResponse(json.dumps("response"), status_code=200) except Exception as ex: conn.rollback() conn.close() logging.exception(f"Exception occurred while updating - {ex}") return func.HttpResponse("Something Went Wrong!", status_code=500) else: return func.HttpResponse("No Parameters Passed", status_code=500) return func.HttpResponse("status of records are updated", status_code=200)
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Getting all the users.') conn = connection.getconnection() if conn: crsr = conn.cursor() get_sql = f"SELECT * from [dbo].[Users]" try: crsr.execute(get_sql) items = [] for row in crsr.fetchall(): datarow = {} datarow["userName"] = row.UserName datarow["name"] = row.Name datarow["surname"] = row.Surname datarow["emailAddress"] = row.EmailAddress datarow["isActive"] = row.IsActive datarow["id"] = row.Id items.append(datarow) crsr.commit() conn.close() if items: return func.HttpResponse(json.dumps(items), status_code=200) else: return func.HttpResponse("No Record Found", status_code=200) except Exception: conn.close() logging.exception(f"Exception occurred while updating - {ex}") return func.HttpResponse("Something Went Wrong!", status_code=500)
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Resetting the password.') req_response = req.get_json() if req_response: AdminPassword = req_response.get('adminPassword') NewPassword = req_response.get('newPassword') UserId = req_response.get('userId') LastModificationTime = dt_Kl.strftime('%Y-%m-%d %H:%M:%S') LastModifierUserId = req_response.get('modifierUserId') conn = connection.getconnection() if conn: crsr = conn.cursor() update_sql = f"UPDATE [dbo].[Users] SET Password = '******',LastModificationTime='{LastModificationTime}', LastModifierUserId = '{LastModifierUserId}' where Id = '{UserId}'" try: crsr.execute(update_sql) crsr.execute("select @@rowcount") rowcount = crsr.fetchall()[0][0] if rowcount>0: response = {"result": 'true', "targetUrl": 'null', "success": 'true', "error": 'null', "unAuthorizedRequest": 'false', "__abp": 'true' } crsr.commit() conn.close() return func.HttpResponse( json.dumps(response), status_code=200 ) except Exception as ex: conn.rollback() conn.close() logging.exception(f"Exception occurred while resetting the password - {ex}") return func.HttpResponse( "Something Went Wrong!", status_code=500 ) else: return func.HttpResponse( "No Parameters Passed", status_code=500 )
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Getting the information of a user.') req_response = req.get_json() if req_response: if 'Id' in req_response.keys(): Getkey = req_response['Id'] else: return func.HttpResponse("Invalid Parameters to Get a User", status_code=404) conn = connection.getconnection() if conn: crsr = conn.cursor() get_sql = f"SELECT * from [dbo].[Users] where Id = {Getkey}" try: crsr.execute(get_sql) response = {} for row in crsr.fetchall(): response["userName"] = row.UserName response["name"] = row.Name response["surname"] = row.Surname response["emailAddress"] = row.EmailAddress response["isActive"] = row.IsActive response["id"] = row.Id crsr.commit() conn.close() if response: return func.HttpResponse(json.dumps(response), status_code=200) else: return func.HttpResponse("No Record Found", status_code=404) except Exception as ex: conn.rollback() conn.close() logging.exception( f"Exception occurred while getting the record - {ex}") return func.HttpResponse("Something Went Wrong!", status_code=500) else: return func.HttpResponse("No Parameters Passed", status_code=500)
def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Creating a user.') req_response = req.get_json() if req_response: id1=req_response.get('id') EmailAddress=req_response.get('emailaddress') IsActive=req_response.get('isActive') Name=req_response.get('Name') Password=req_response.get('password') Surname=req_response.get('surname') UserName=req_response.get('username') CreationTime=dt.strftime('%Y-%m-%d %H:%M:%S') LastModificationTime=dt.strftime('%Y-%m-%d %H:%M:%S') conn = connection.getconnection() if conn: crsr=conn.cursor() query="INSERT INTO [dbo].[Users] (AccessFailedCount,AuthenticationSource,CreationTime,CreatorUserId,DeleterUserId,DeletionTime,EmailAddress,EmailConfirmationCode,IsActive,IsDeleted,IsEmailConfirmed,IsLockoutEnabled,IsPhoneNumberConfirmed,IsTwoFactorEnabled,LastModificationTime,LastModifierUserId,LockoutEndDateUtc,Name,Password,PasswordResetCode,PhoneNumber,Surname,UserName) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);" records=[(0,None,CreationTime,None,None,None,EmailAddress,None,IsActive,0,0,1,0,0,LastModificationTime,None,None,Name,Password,None,None,Surname,UserName)] try: crsr.executemany(query,records) response={'id':id1,"emailaddress":EmailAddress,'username':UserName} crsr.commit() conn.close() return func.HttpResponse(json.dumps(response),status_code=200) except Exception as ex: conn.rollback() conn.close() logging.exception(f"Exception occurred while creating a user - {ex}") return func.HttpResponse( "Something Went Wrong!", status_code=500 ) else: return func.HttpResponse( "No Parameters Passed", status_code=500 )