示例#1
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <bool> FunctionHandler(ResendTemporaryCodeRequest input, ILambdaContext context)
        {
            LambdaLogger.Log(input.ToString <ResendTemporaryCodeRequest>());
            CognitoService helper = new CognitoService();

            return(await helper.ResendTemporaryPasssword(input));
        }
示例#2
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <bool> FunctionHandler(ResetPasswordRequest request, ILambdaContext context)
        {
            CognitoService helper   = new CognitoService();
            var            response = await helper.ResetPassword(request);

            return(true);
        }
示例#3
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task <string> FunctionHandler(ConfirmSignUpRequest request, ILambdaContext context)
        {
            CognitoService helper = new CognitoService();
            await helper.ConfirmSignUp(request);

            return(request.ToString <ConfirmSignUpRequest>());
        }
示例#4
0
 public AuthController(ILogger <AuthController> logger,
                       ConfigClient configClient,
                       CognitoService cognitoService)
 {
     this.logger         = logger;
     this.cognitoService = cognitoService;
 }
示例#5
0
        public PublicCalendarMutation(
            CalendarDbFactory dbFactory,
            CalendarRequestDecorator requestDecorator,
            IUserOwnedGenericRepository <Tab> tabRepository,
            IUserOwnedGenericRepository <Event> eventRepository,
            IUserOwnedGenericRepository <UserPreference> userPreferenceRepository,
            IUserRepository userRepository,
            CognitoService cognitoService) : base(requestDecorator)
        {
            AddFieldAsync <Tab, GraphQLTab, GraphQLTabInput>("Tab", tabRepository);
            AddFieldAsync <Event, GraphQLEvent, GraphQLEventInput>("Event", eventRepository);
            AddSingleFieldAsync <UserPreference, GraphQLUserPreference, GraphQLUserPreferenceInput>("UserPreference", userPreferenceRepository);

            AddUserAsync(userRepository, cognitoService, dbFactory);
        }
示例#6
0
 public UserController(CognitoService CognitoService, DynamoContext DBDynamo, IMapper Mapper)
 {
     _CognitoService = CognitoService;
     _DBDynamo       = DBDynamo;
     _Mapper         = Mapper;
 }
示例#7
0
        protected void AddUserAsync(IUserRepository repository, CognitoService cognitoService, CalendarDbFactory dbFactory)
        {
            FieldAsync <NonNullGraphType <BooleanGraphType> >(
                "signUp",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <GraphQLUserSignUpInput> > {
                Name = "signUpData"
            }
                    ),
                resolve: async resolveContext => {
                return(await _requestDecorator.Run(resolveContext, async context => {
                    using (var dbContext = dbFactory.CreateDbContext())
                    {
                        var data = context.GetArgument <UserWithPassword>("signUpData");
                        await cognitoService.SignUpAsync(data.Email, data.Password);

                        var createData = context.GetArgument <User>("signUpData");
                        createData.DateCreated = DateTime.Now.ToUniversalTime();
                        createData.LastVisitDate = DateTime.Now.ToUniversalTime();

                        await repository.AddAsync(createData);

                        return true;
                    }
                }));
            });

            FieldAsync <NonNullGraphType <GraphQLLoginInfo> >(
                "login",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <GraphQLUserLoginInput> > {
                Name = "loginData"
            }
                    ),
                resolve: async resolveContext => {
                return(await _requestDecorator.Run(resolveContext, async context => {
                    using (var dbContext = dbFactory.CreateDbContext())
                    {
                        var data = context.GetArgument <UserWithPassword>("loginData");

                        // TODO: remove to repository
                        var user = dbContext.Users.SingleOrDefault(x => x.Email == data.Email);

                        if (user == null)
                        {
                            throw new CalendarException($"User with email: {data.Email} is not found");
                        }

                        var token = await cognitoService.LoginAsync(data.Email, data.Password, data.NewPasswordIfRequired);

                        await repository.UpdateLoginAsync(data.Email);

                        var loginInfo = new LoginInfo
                        {
                            User = user,
                            Token = token,
                            ExpiresAt = DateTime.Now
                                        .ToUniversalTime()
                                        .AddHours(1)
                                        .Subtract(new DateTime(1970, 1, 1))
                                        .TotalSeconds
                                        .ToString()
                        };

                        return loginInfo;
                    }
                }));
            });

            FieldAsync <NonNullGraphType <BooleanGraphType> >(
                "confirmUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <GraphQLUserConfirmInput> > {
                Name = "confirmUser"
            }
                    ),
                resolve: async resolveContext => {
                return(await _requestDecorator.Run(resolveContext, async context => {
                    var data = context.GetArgument <ConfirmUser>("confirmUser");

                    await cognitoService.ConfirmUserAsync(data.Email, data.ConfirmationCode);

                    return true;
                }));
            });

            FieldAsync <NonNullGraphType <BooleanGraphType> >(
                "changePassword",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <GraphQLUserChangePasswordInput> > {
                Name = "changePassword"
            }
                    ),
                resolve: async resolveContext => {
                return(await _requestDecorator.Run(resolveContext, async context => {
                    var data = context.GetArgument <ChangePassword>("changePassword");

                    await cognitoService.ChangePasswordAsync(data.Token, data.OldPassword, data.NewPassword);

                    return true;
                }));
            });

            FieldAsync <NonNullGraphType <BooleanGraphType> >(
                "forgotPassword",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <GraphQLUserForgotPasswordInput> > {
                Name = "forgotPassword"
            }
                    ),
                resolve: async resolveContext => {
                return(await _requestDecorator.Run(resolveContext, async context => {
                    var data = context.GetArgument <ForgotPassword>("forgotPassword");

                    await cognitoService.ForgotPasswordAsync(data.Email);

                    return true;
                }));
            });

            FieldAsync <NonNullGraphType <BooleanGraphType> >(
                "confirmForgotPassword",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <GraphQLUserConfirmForgotPasswordInput> > {
                Name = "confirmForgotPassword"
            }
                    ),
                resolve: async resolveContext => {
                return(await _requestDecorator.Run(resolveContext, async context => {
                    var data = context.GetArgument <ConfirmForgotPassword>("confirmForgotPassword");

                    await cognitoService.ConfirmForgotPasswordAsync(data.Email, data.ConfirmationCode, data.NewPassword);

                    return true;
                }));
            });

            FieldAsync <NonNullGraphType <BooleanGraphType> >(
                "adminInviteUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <GraphQLAdminInviteUserInput> > {
                Name = "adminInviteUser"
            }
                    ),
                resolve: async resolveContext => {
                return(await _requestDecorator.Run(resolveContext, async context => {
                    var data = context.GetArgument <AdminInviteUser>("adminInviteUser");

                    await cognitoService.AdminInviteUserAsync(data.Email);

                    return true;
                }));
            });

            FieldAsync <NonNullGraphType <BooleanGraphType> >(
                "adminChangeUserPassword",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <GraphQLAdminChangeUserPasswordInput> > {
                Name = "adminChangeUserPassword"
            }
                    ),
                resolve: async resolveContext => {
                return(await _requestDecorator.Run(resolveContext, async context => {
                    var data = context.GetArgument <AdminChangeUserPassword>("adminChangeUserPassword");

                    await cognitoService.AdminChangeUserPassword(data.Email, data.Password);

                    return true;
                }));
            });

            FieldAsync <NonNullGraphType <IntGraphType> >(
                $"updateUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <GraphQLUserInput> > {
                Name = "updateData"
            }
                    ),
                resolve: async resolveContext =>
            {
                return(await _requestDecorator.Run(resolveContext, async context =>
                {
                    var id = context.GetArgument <int>("id");
                    var updateData = context.GetArgument <User>("updateData");

                    var dbUser = await repository.GetAsync(id);

                    dbUser.Image = updateData.Image;
                    dbUser.Phone = updateData.Phone;

                    await repository.UpdateAsync(id, updateData);
                    return id;
                }));
            });

            FieldAsync <NonNullGraphType <IntGraphType> >(
                $"deleteUser",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }
                    ),
                resolve: async resolveContext => {
                return(await _requestDecorator.Run(resolveContext, async context => {
                    var id = context.GetArgument <int>("id");
                    await repository.DeleteAsync(id);
                    return id;
                }));
            });
        }